[Patches] [ python-Patches-716969 ] fix thread bug in 2.2.2 and later

SourceForge.net noreply@sourceforge.net
Sat, 19 Apr 2003 00:47:26 -0700

Patches item #716969, was opened at 2003-04-07 22:04
Message generated for change (Comment added) made by loewis
You can respond by visiting: 

Category: Core (C code)
Group: None
>Status: Closed
>Resolution: Accepted
Priority: 5
Submitted By: Greg Klanderman (gregklanderman)
Assigned to: Martin v. L÷wis (loewis)
Summary: fix thread bug in 2.2.2 and later

Initial Comment:
in at least 2.2.2 and later (and probably earlier), the
pthread implementation of thread.create_new_thread() is
no longer handling the inability to create a new thread
properly - it returns as though a new thread was
created but in fact no thread was started.

the bug seems to have been introduced here:

> revision 2.35
> date: 2001/10/16 21:13:49;  author: gvanrossum;  ...
> Partial patch from SF #452266, by Jason Petrone.
> This changes Pythread_start_thread() to return the
thread ID, or -1
> for an error.  (It's technically an incompatible API
change, but I
> doubt anyone calls it.)

it apepars that the same bug may exist in the nt and
solaris thread implementations though i was not able to
test this hypothesis.

here's a test script to run 

import thread, time, traceback

def foo(i):
  print "thread %3d finished" % (i,)

for i in range(3000):
    v = thread.start_new_thread(foo, (i,))
    print "started thread %d --> %s" % (i, v)
  except thread.error, e:
    print "thread limit reached: %d" % (i,)


you'll notice that on 1.5.2, after around 256 threads
are created, an error is raised, and that all the
threads prior to this then complete a few seconds
later.  in 2.2.2, an error is never raised, but only
about 1000 threads have actually been successfully

patch is attached.  i've taken the liberty of renaming
one of the variables for clarity.



>Comment By: Martin v. L÷wis (loewis)
Date: 2003-04-19 09:47

Logged In: YES 

Thanks for the patch. I believe you are right about Solaris
threads, and have applied the "obvious" fix; committed
everything as

thread_pthread.h 2.46
thread_solaris.h 2.19


You can respond by visiting: