Problems with threads

Tim Peters tim_one at email.msn.com
Wed Sep 1 21:14:23 EDT 1999


[Dominic Hillenbrand]
> I have written a short program that goes like this:
>
> s = Semaphore(MAX_THREADS)
>
> while 1:
>    listen on server port
>    accept request
>    s.aquire()
>    start_new_thread(serve_client, (socket, ))
>
> def serve_client(s):
>    do something important
>    global s
>    s .release()
>
> This code produces this type of error message:
>
> currentThread(): no current thread for 1025
> currentThread(): no current thread for 2050
> (.....)
>
> The program still seems to run correct!!!
> But what is the reason for the error message?

You haven't posted what is likely the key point:  unless I miss my guess,
you're importing Semaphore from threading.py but start_new_thread from the
bare-bones thread.py.  threading.py doesn't know anything about threads you
create from the lower-level thread.py, so whenever one of the latter tries to
do an operation on an object created by the former, the former can't find the
information it expects to find for threads *it* creates.  It probably won't
blow up, but Don't Do That is good advice anyway -- if you're going to use
threading.py, use it for everything (including thread creation).

> ...
> P.S. Will there be Python support for the linuxthreads semaphores ?

Doubt it -- Python doesn't offer any platform-specific thread gimmicks.  If
someone cares enough about this (or any other) platform gimmick, they're
welcome to write an extension module and share it, though.

albeit-that-they're-also-welcome-not-to-ly y'rs  - tim






More information about the Python-list mailing list