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

SourceForge.net noreply@sourceforge.net
Mon, 07 Apr 2003 22:56:53 -0700


Patches item #716969, was opened at 2003-04-07 22:04
Message generated for change (Settings changed) made by loewis
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=716969&group_id=5470

Category: Core (C code)
Group: None
Status: Open
Resolution: None
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:

Python/thread_pthread.h:
> 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):
  time.sleep(10)
  print "thread %3d finished" % (i,)

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

time.sleep(30)

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
created.

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

greg
gak@klanderman.net


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=716969&group_id=5470