About Threading - implementation

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Wed Jun 14 06:42:28 EDT 2006


In <mailman.7020.1150278560.27775.python-list at python.org>, Dara Durum
wrote:

> Under Python the threads are simulated by Python Interpreter as when
> prev. setted pieces (interval) of the interpreted tokens are executed,
> it is change to another "virtual" thread ?
> 
> Or it was really create real threads, and they are figth for the
> priority, and for the execution time ?

Both.  CPython creates real threads but only one of those can be active at
a time if python bytecode is executed because of the `global interpreter
lock` (GIL).  Extensions written in C can release that lock unless they
are accessing the interpreter "internals".  For example blocking IO calls
like `file.read()` release the lock.

> And can I create REAL threads under Python (just like in Delphi), or
> better if I use processes, not threads ?

Depends on the use case.  If your program is IO bound i.e. many threads
waiting for blocking IO then just use Python threads.  If your task is
computational intensive then it may be better to use processes and some
form of inter process communication.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list