[Stackless] Mixing os threads and stackless
Lars Immisch
lars at ibp.de
Wed Apr 26 13:31:26 CEST 2006
Hi,
> I don't *think* you'd get much advantage with this as the python global
> interpreter lock will block all threads while another is executing so
> you might as well run a single thread with all your tasklets in it?
Umm, yes. Having multiple OS threads to run multiple *pure Python*
tasklets each seems pretty much pointless.
> Unless ofcourse you have specific C routines in your code that get
> called into often that release the interpreter lock? Your best bet is
> probably to run some tests in your application and see which gives the
> best performance.
Or you use a blocking function from the Python library, or a function
from a third-party module, like a blocking database adapter.
<diversion>
All blocking functions, like sleep(), poll() or whatever will release
and reacquire the GIL (if threading is enabled - it normally is)
If you write C-Extensions, you need to call PyEval_InitThreads, and
bracket your blocking calls like:
Py_BEGIN_ALLOW_THREADS
...Do some blocking I/O operation...
Py_END_ALLOW_THREADS
</diversion>
- Lars
_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless
More information about the Stackless
mailing list