From harrisbw at notes.udayton.edu Mon Aug 4 19:34:58 2008 From: harrisbw at notes.udayton.edu (Bryan Harris) Date: Mon, 4 Aug 2008 13:34:58 -0400 Subject: [CentralOH] Python threads Message-ID: <16d1d1250808041034t350c995fv3d66dcff3cac4130@mail.gmail.com> Hi all, Does anybody have any experience with threads in Python. I wanted to play with threads in python so I pulled down this code which looked like a good starting place. (First or second page of Google.) It is obviously supposed to spawn 20 threads that then sleep for a random time. The proof would be that they report back out of order. What really happens is that the threads report back in order with random waits in between. Obviously sleep isn't releasing the current thread. Is there some way to tell if you have threading support in the interpreter you're running? I read the "threading" module will import dummy_threads if you don't have threading support. How can you tell? import threading import time import random theVar = 1 class MyThread ( threading.Thread ): def run ( self ): global theVar time.sleep(random.random()*10) print 'This is thread ' + str ( theVar ) + ' speaking.' print 'Hello and good bye.' theVar = theVar + 1 for x in xrange ( 20 ): MyThread().start() -- Bryan Harris Research Engineer Structures and Materials Evaluation Group harrisbw at notes.udayton.edu http://www.udri.udayton.edu/ (937) 229-5561 From steven_h at acm.org Mon Aug 4 20:23:33 2008 From: steven_h at acm.org (Steven Huwig) Date: Mon, 4 Aug 2008 14:23:33 -0400 Subject: [CentralOH] Python threads In-Reply-To: <16d1d1250808041034t350c995fv3d66dcff3cac4130@mail.gmail.com> References: <16d1d1250808041034t350c995fv3d66dcff3cac4130@mail.gmail.com> Message-ID: <7505f2a60808041123l38e9aeetc4506f3ef9e46137@mail.gmail.com> Your global counter is the problem. You should give the thread its own number before you start the thread. import threading import time import random class MyThread ( threading.Thread ): def __init__(self, num): threading.Thread.__init__(self) self.num = num def run ( self ): time.sleep(random.random()*10) print 'This is thread ' + str ( self.num ) + ' speaking.' print 'Hello and good bye.' for x in xrange ( 20 ): MyThread(x).start() From nludban at osc.edu Mon Aug 4 20:08:13 2008 From: nludban at osc.edu (Neil Ludban) Date: Mon, 4 Aug 2008 14:08:13 -0400 Subject: [CentralOH] Python threads In-Reply-To: <16d1d1250808041034t350c995fv3d66dcff3cac4130@mail.gmail.com> References: <16d1d1250808041034t350c995fv3d66dcff3cac4130@mail.gmail.com> Message-ID: <20080804140813.c4f02a83.nludban@osc.edu> On Mon, 4 Aug 2008 13:34:58 -0400 "Bryan Harris" wrote: > It is obviously supposed to spawn 20 threads that then sleep for a > random time. The proof would be that they report back out of order. > What really happens is that the threads report back in order with > random waits in between. Obviously sleep isn't releasing the current > thread. Threading is probably working fine, the example is obviously broken. Improved, but not perfect: > def run ( self ): > > global theVar myVar = theVar theVar = theVar + 1 > time.sleep(random.random()*10) > ###print 'This is thread ' + str ( theVar ) + ' speaking.' print 'This is thread ' + str ( myVar ) + ' speaking.' > print 'Hello and good bye.' > ###theVar = theVar + 1 From harrisbw at notes.udayton.edu Mon Aug 4 20:51:41 2008 From: harrisbw at notes.udayton.edu (Bryan) Date: Mon, 04 Aug 2008 14:51:41 -0400 Subject: [CentralOH] Python threads In-Reply-To: <7505f2a60808041123l38e9aeetc4506f3ef9e46137@mail.gmail.com> References: <16d1d1250808041034t350c995fv3d66dcff3cac4130@mail.gmail.com> <7505f2a60808041123l38e9aeetc4506f3ef9e46137@mail.gmail.com> Message-ID: <1217875901.1433.18.camel@bryan-udri.udri.udayton.edu> Yep Thanks! It wasn't somehow blocking somewhere as I had suspected. :-p It was doing what I told it to do.... This works as well without the init: import threading import time import random theVar = 1 class MyThread ( threading.Thread ): def run ( self ): global theVar myNumber = theVar theVar = theVar + 1 time.sleep(random.random()*10) print 'This is thread ' + str ( myNumber ) + ' speaking.\nHello and good bye.' for x in xrange ( 200 ): MyThread().start() On Mon, 2008-08-04 at 14:23 -0400, Steven Huwig wrote: > Your global counter is the problem. You should give the thread its own > number before you start the thread. > > import threading > import time > import random > > class MyThread ( threading.Thread ): > def __init__(self, num): > threading.Thread.__init__(self) > self.num = num > > def run ( self ): > time.sleep(random.random()*10) > print 'This is thread ' + str ( self.num ) + ' speaking.' > print 'Hello and good bye.' > > for x in xrange ( 20 ): > MyThread(x).start() -- Bryan Harris Research Engineer Structures and Materials Evaluation Group harrisbw at notes.udayton.edu http://www.udri.udayton.edu/ (937) 229-5561 From harrisbw at notes.udayton.edu Mon Aug 4 20:46:03 2008 From: harrisbw at notes.udayton.edu (Bryan) Date: Mon, 04 Aug 2008 14:46:03 -0400 Subject: [CentralOH] Python threads In-Reply-To: <7505f2a60808041123l38e9aeetc4506f3ef9e46137@mail.gmail.com> References: <16d1d1250808041034t350c995fv3d66dcff3cac4130@mail.gmail.com> <7505f2a60808041123l38e9aeetc4506f3ef9e46137@mail.gmail.com> Message-ID: <1217875563.1433.14.camel@bryan-udri.udri.udayton.edu> Thanks! I never would have figured that one out myself. It makes sense now. I think the threads _were_ actually running concurrently, they just weren't being given a number based on their start order. On Mon, 2008-08-04 at 14:23 -0400, Steven Huwig wrote: > Your global counter is the problem. You should give the thread its own > number before you start the thread. > > import threading > import time > import random > > class MyThread ( threading.Thread ): > def __init__(self, num): > threading.Thread.__init__(self) > self.num = num > > def run ( self ): > time.sleep(random.random()*10) > print 'This is thread ' + str ( self.num ) + ' speaking.' > print 'Hello and good bye.' > > for x in xrange ( 20 ): > MyThread(x).start() -- Bryan Harris Research Engineer Structures and Materials Evaluation Group harrisbw at notes.udayton.edu http://www.udri.udayton.edu/ (937) 229-5561 From catherine.devlin at gmail.com Tue Aug 5 20:32:52 2008 From: catherine.devlin at gmail.com (Catherine Devlin) Date: Tue, 5 Aug 2008 14:32:52 -0400 Subject: [CentralOH] Ohio LinuxFest Message-ID: <6523e39a0808051132x66a51b10n4e6d52a93029511c@mail.gmail.com> Hey everybody, Remember, talk submissions for Ohio Linuxfest are due August 15. Got something to delight the FOSS crowd (and maybe expose them to some Python, too)? Submit it! http://ohiolinux.org/ The Fest is Oct. 10-11 in Columbus. I'm trying to think of a talk I could submit myself... I'd take suggestions! Also, here's an idea I'm scheming on - not as a formal talk: Would folks be interested in a table at Ohio LinuxFest to publicize Python and PyOhio? Here's what I'm imagining: - Table - Friendly volunteer to chat about python or whatnot - Laptop with big screen, running demos of nifty Python tricks (I can supply this) - PyOhio flyers - Info sheets to hand out: What is Python, Getting Started with Python, ... - Highly affordable swag: "Python" stickers (like the ones from PyCon)* Uh... PyOhio postcards? Then, to capitalize on it all, we offer an intro Python workshop late in the day. Other ideas? More importantly, volunteers to staff the booth? We should have multiple volunteers, so no one person has to give up too much LinuxFest. Of course, staffing the booth should be worthwhile in itself. -- - Catherine http://catherinedevlin.blogspot.com/ *** PyOhio 2008 * Columbus * July 26, 2008 * pyohio.org *** From mark at microenh.com Wed Aug 6 04:51:33 2008 From: mark at microenh.com (Mark Erbaugh) Date: Tue, 05 Aug 2008 22:51:33 -0400 Subject: [CentralOH] Python vs. Apache Message-ID: <1217991094.23565.6.camel@P1900> I want to do some server side programming in Python for my Apache server. From what I've seen there are a bunch of different ways to do it. CGI mod_python mod_wsgi / fastcgi or fcgi / wsgiref wsgiref ??? Is there a 'preferred' method? Is there a document that compares various approaches? I understand the limitations of pure CGI as Python has to be started for every request. At this point, I'm looking to do the programming in Python so I'm not considering a Python-based web framework. Mark From jglands at att.net Wed Aug 6 05:19:16 2008 From: jglands at att.net (Jesse Lands) Date: Tue, 5 Aug 2008 20:19:16 -0700 (PDT) Subject: [CentralOH] Python vs. Apache In-Reply-To: <1217991094.23565.6.camel@P1900> Message-ID: <293817.77933.qm@web80014.mail.sp1.yahoo.com> My personal preference is mod_python. Not sure about comparison or docs, but here is a post from the mod_python list. http://www.modpython.org/pipermail/mod_python/2006-December/022841.html Jesse -------------- next part -------------- An HTML attachment was scrubbed... URL: From gacsinger at gmail.com Wed Aug 6 13:54:45 2008 From: gacsinger at gmail.com (Greg Singer) Date: Wed, 6 Aug 2008 07:54:45 -0400 Subject: [CentralOH] Python vs. Apache In-Reply-To: <1217991094.23565.6.camel@P1900> References: <1217991094.23565.6.camel@P1900> Message-ID: If you're just experimenting or if server load isn't a big deal then basic CGI is by far the easiest method to start with. Plus, it's easy to migrate over to mod_python or one of the other methods in the future if performance becomes an issue. - Greg On Tue, Aug 5, 2008 at 10:51 PM, Mark Erbaugh wrote: > I want to do some server side programming in Python for my Apache > server. From what I've seen there are a bunch of different ways to do > it. > > CGI > mod_python > mod_wsgi / fastcgi or fcgi / wsgiref > wsgiref > ??? > > Is there a 'preferred' method? Is there a document that compares > various approaches? From wam at cisco.com Wed Aug 6 17:49:03 2008 From: wam at cisco.com (William McVey) Date: Wed, 06 Aug 2008 11:49:03 -0400 Subject: [CentralOH] Python vs. Apache In-Reply-To: <1217991094.23565.6.camel@P1900> References: <1217991094.23565.6.camel@P1900> Message-ID: <1218037744.6311.35.camel@tardis> On Tue, 2008-08-05 at 22:51 -0400, Mark Erbaugh wrote: > I want to do some server side programming in Python for my Apache > server. From what I've seen there are a bunch of different ways to do > it. > > CGI > mod_python > mod_wsgi / fastcgi or fcgi / wsgiref > wsgiref Don't forget the option of building on top of BaseHTTPServer (or SimpleHTTPServer) as well as the option of using the twisted web server. All this can be seamlessly integrated into an Apache based website with a mod-rewrite rule that reverse proxies requests to the python-based service running on another port. > Is there a 'preferred' method? Yes, there are many preferred methods. The problem is that set of preferred methods vary depending on the developer you ask and even in some cases the project that developer is working on. > Is there a document that compares > various approaches? It's not really comparing, but it's worth reviewing: http://wiki.python.org/moin/WebProgramming and http://wiki.python.org/moin/WebFrameworks > I understand the limitations of pure CGI as Python has to be started for > every request. Not quite always the case. If your CGI scripts are written in python, you can use mod_python.cgihandler to execute those scripts without forking additional copies of python (with some caveats related to thread management). I'm certainly not advocating this approach, but it is important to know where the true limits are. > At this point, I'm looking to do the programming in Python so I'm not > considering a Python-based web framework. Programming an application using a full stack web framework such as Django or TurboGears *is* programming in python, so implying that you are not considering these frameworks because you want to program in python doesn't make sense to me. If anything, web apps coded using these frameworks generally have a higher percentage of python code than other approaches since you generally don't have to have embedded SQL or HTML in your application. More importantly though is that a "framework" is just a set of generally useful functionality that has been provided to you so that you don't have to implement that functionality in your own code. Packages like mod_wsgi, wsgiref, mod_python and even cgi.py are all web development frameworks. They may not be full-stack frameworks that provide all the functionality of something like Django or Turbogears, but they're providing the application writer an easier to use or more powerful interface for building their app than if that framework didn't exist. It's also important to realize that even with the full stack frameworks, most of the provided functionality is optional. For example, if you don't need middleware, you don't need to enable it. If you don't want object to relational database mapping, you don't have to use it. -- William From pythondevdang at lazytwinacres.net Sat Aug 9 15:11:04 2008 From: pythondevdang at lazytwinacres.net (Daniel 'Dang' Griffith) Date: Sat, 09 Aug 2008 09:11:04 -0400 Subject: [CentralOH] Mathematics and Database Design In-Reply-To: References: Message-ID: <6.2.3.4.2.20080809090721.02294698@mail.lazytwinacres.net> There was a guy at PyOhio, "Nugent", who I spoke with briefly about a book on the mathematics of [relational] database design. I'm wondering if he's on this list, and if so, would he please let me know the book title, ISBN, author, etc. Or, if anyone else out there has heard of such a book. I'm looking for some rigorous backing to explain/justify some of my data model design decisions. Or refute them, of course, if I've been doing it wrong (ahem). Thanks, --dang From wam at cisco.com Mon Aug 11 16:39:44 2008 From: wam at cisco.com (William McVey) Date: Mon, 11 Aug 2008 10:39:44 -0400 Subject: [CentralOH] Mathematics and Database Design In-Reply-To: <6.2.3.4.2.20080809090721.02294698@mail.lazytwinacres.net> References: <6.2.3.4.2.20080809090721.02294698@mail.lazytwinacres.net> Message-ID: <1218465584.6277.3.camel@tardis> On Sat, 2008-08-09 at 09:11 -0400, Daniel 'Dang' Griffith wrote: > There was a guy at PyOhio, "Nugent", who I spoke with briefly about a > book on the mathematics of [relational] database design. I'm wondering > if he's on this list, and if so, would he please let me know the book title, > ISBN, author, etc. > > Or, if anyone else out there has heard of such a book. I'm looking for > some rigorous backing to explain/justify some of my data model design > decisions. Or refute them, of course, if I've been doing it wrong (ahem). I'm not exactly sure which book "Nugent" might have been referring to, but here are some possible contenders: Applied Mathematics for Database Professionals http://www.apress.com/book/view/1590597451 Database in Depth: Relational Theory for Practitioners http://oreilly.com/catalog/9780596100124/index.html -- William From mark at microenh.com Mon Aug 11 19:02:33 2008 From: mark at microenh.com (Mark Erbaugh) Date: Mon, 11 Aug 2008 13:02:33 -0400 Subject: [CentralOH] XML Message-ID: <1218474153.22141.3.camel@P1900> I'm parsing some XML generated by JavaScript in a web browser. When the browser is Internet Explorer (I've only tested v 6), a boolean is returned as "-1" (true) or "0" (false). When the browser is not IE (I've tested Mozilla, Firefox and Opera), booleans are returned as "true" or "false". Is there a standard way to convert these values to Python bool's or do I just need to do string comparisons? Do other browser's return different values? Thanks, Mark From mark at microenh.com Mon Aug 11 20:00:38 2008 From: mark at microenh.com (Mark Erbaugh) Date: Mon, 11 Aug 2008 14:00:38 -0400 Subject: [CentralOH] Web Server Response Message-ID: <1218477638.25024.6.camel@P1900> I'm working on a Python web server that allow users to update a database using a browser. It's possible that the user could submit a database update that is disallowed by the database server, i.e. deleting a row that is a referenced by a foreign key or inserting a duplicate key. Is there an HTTP status code that can be used for the response? I could use 400 (bad request), but is there a better choice? Thanks, Mark From samus at codeargyle.com Mon Aug 11 19:42:10 2008 From: samus at codeargyle.com (Sam Corder) Date: Mon, 11 Aug 2008 13:42:10 -0400 (EDT) Subject: [CentralOH] Web Server Response In-Reply-To: <1218477638.25024.6.camel@P1900> Message-ID: <4931682.2401218476530109.JavaMail.root@spring.codeargyle.com> It really depends. Most of the time people don't bother with the response code and just output a 200 OK and a message to the browser client saying that you can't do that. If you're working on this for more of a machine to machine communication style I'd definitely go with one of the 400 level codes. ----- Original Message ----- From: Mark Erbaugh To: centraloh at python.org Sent: Monday, August 11, 2008 2:00:38 PM GMT-0500 Auto-Detected Subject: [CentralOH] Web Server Response I'm working on a Python web server that allow users to update a database using a browser. It's possible that the user could submit a database update that is disallowed by the database server, i.e. deleting a row that is a referenced by a foreign key or inserting a duplicate key. Is there an HTTP status code that can be used for the response? I could use 400 (bad request), but is there a better choice? Thanks, Mark _______________________________________________ CentralOH mailing list CentralOH at python.org http://mail.python.org/mailman/listinfo/centraloh From wam at cisco.com Mon Aug 11 23:08:57 2008 From: wam at cisco.com (William McVey) Date: Mon, 11 Aug 2008 17:08:57 -0400 Subject: [CentralOH] Web Server Response In-Reply-To: <1218477638.25024.6.camel@P1900> References: <1218477638.25024.6.camel@P1900> Message-ID: <1218488938.6277.15.camel@tardis> On Mon, 2008-08-11 at 14:00 -0400, Mark Erbaugh wrote: > I'm working on a Python web server that allow users to update a database > using a browser. It's possible that the user could submit a database > update that is disallowed by the database server, i.e. deleting a row > that is a referenced by a foreign key or inserting a duplicate key. > > Is there an HTTP status code that can be used for the response? I could > use 400 (bad request), but is there a better choice? Note that error code 400 is used to convey that the server was unable to parse or otherwise understand the request. It's not a generic "failure" because the request was "bad". Some error codes that seem like they might be appropriate include: * 401 Unauthorized * 403 Forbidden * 405 Method Not Allowed That last one should probably only be used if your service is truly a RESTful interface, in that each resource (e.g. a row in the table) has it's own URI. Presumably this would be in response to a POST or DELETE method type, and your reply would indicate that only 'GET' is acceptable. These error codes are all defined in section 10 of RFC 2616 defining HTTP/1.1 (viewable at http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10 ). -- William