Movatterモバイル変換


[0]ホーム

URL:


Win32 and blocking threads

David Bolendb3l at fitlinxx.com
Mon Apr 23 12:43:07 EDT 2001


Campbell <cb921 at voice.co.za> writes:> Are Python/win32 Threads == Windows threads?  Or are they, in the style> of ActivePerl's Threads, rather braindead?  I know this is a FAQ of> sorts but I have read that document and many others in confusion still.Yes, under Win32, Python threads are Win32 threads and thus OSthreads.  We use them all the time in our code and they work verynicely with various blocking operations.However (and this is important), Python overall still uses a globalinterpreter lock to control its execution of the interpreted code.  Soeven though you can have multiple OS threads, if any of them blockwhile still holding the GIL, it will prevent any of your other Pythoncode from running.  Python code itself won't have this problem (theinterpreter releases the GIL periodically after processing a smallnumber of opcodes), but internal C code within the Python interpreteror in extension modules can do this.In general, anytime the Python interpreter itself (or its standardmodules) make calls to the OS that might block, it will release theGIL around the code, permitting other Python code to run.  The same isgenerally true for extension modules.  However, if a piece of codeforgets to do this, then the blocking operation can also block otherPython threads.So an important question here is likely to ask precisely what blockingcall are you using in your threads, and if that call is from someextension module, has that extension module properly released the GILacross the call?---- David-- /-----------------------------------------------------------------------\ \               David Bolen            \   E-mail:db3l at fitlinxx.com  /  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    | /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \\-----------------------------------------------------------------------/


More information about the Python-listmailing list

[8]ページ先頭

©2009-2025 Movatter.jp