basic python threading question

Aahz Maruch aahz at panix.com
Fri Sep 29 15:51:40 EDT 2000


In article <ud7hnngv8.fsf at ctwd0143.fitlinxx.com>,
David Bolen  <db3l at fitlinxx.com> wrote:
>
>In many respects, threading on Python inside of C extension code is
>much simpler than C - at least as far as interacting with the Python
>core - because your code is effectively single threaded when it comes
>to dealing with Python.

That's basically true.

>From a C extension perspective, your C code is only called from within
>a single Python interpreter thread at a time (and is governed by the
>global interpreter lock), so while your C code runs on behalf of a
>Python request, there's only one native thread running against that
>interpreter.  That's also why you want to release the global lock if
>you enter into a blocking operation, or else all Python threads are
>blocked while the one thread calling your function waits for you to
>return.

I think what you really meant to say was that calls into extensions are
serialized, because only one Python thread runs until the extension
releases the GIL.  But as soon as the extension releases the GIL,
another Python thread can call into the extension.
-- 
                      --- Aahz (Copyright 2000 by aahz at pobox.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

Shadows 2000: when you're tired of "Cthulhu for President"  --Aahz



More information about the Python-list mailing list