[ale] James Gosling will be speaking at the Sept.AJUG meeting]

Jason Fritcher jkf at wolfnet.org
Fri Sep 1 01:44:59 EDT 2006


Christopher Fowler wrote:
> I need to do some
> research on the python side to see if it can really do threads.  Maybe
> there is an implementation of pthreads for it?

Threading in Python suffers from one big problem... An interpreter-wide mutex that must be helf before a thread can do anything with python code or objects. Because of this, there is no real concurrency with threading. Although any code that makes blocking IO calls should be ok as the interpreter will release the global lock before making the IO call. On all of the unix platforms I've looked at, Python uses pthreads under the covers, so you are getting real threads to run with. The python locking and conditional constructs have mapped to pthreads constructs. If it wasn't for that Global Interpreter Lock, threading on Python would be awesome. As a preemption mechanism, Python forces a thread to give up the GIL after roughly every 100 opcodes executed. Those are bytecode opcodes and not lines of code, so how much actually runs each timeslice varies.

That all sounds gloom and doom for Python threading, but if you get into writing C extension modules, you can get around a lot of the problems by spawning your own threads from the extension and doing processing outside of the VM. That's what I'm currently doing to create a large scale worker thread pool that is going to be doing boatloads of IO.

-- 
 Jason K. Fritcher
  jkf at wolfnet.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 249 bytes
Desc: OpenPGP digital signature




More information about the Ale mailing list