Thread imbalance

Bryan Olson fakeaddress at nowhere.org
Mon Feb 6 13:52:23 EST 2006


Tuvas wrote:
> The read function used actually is from a library in C, for use over a
> CAN interface. The same library appears to work perfectly find over C.
[...]
> When nothing is happening, the thread runs pretty consistantly at 1
> second. However, when it is doing IO through this C function or
> whatever, the length of time increases, for the time.sleep() function.
> Kind of strange, isn't it? I can explain in more detail if it's needed,
> but I don't know how much it'll help...

That's enough detail that I'll take a most-likely-guess:

When your C function runs, by default you hold the aforementioned
Global Interpreter Lock (GIL). Unless you explicitly release it,
you will hold it until you return, and nothing else will run.
Python's own I/O operations always release the GIL right before
calling any potentially-blocking operation, and reacquire it
right after.

See:

     http://docs.python.org/api/threads.html


-- 
--Bryan



More information about the Python-list mailing list