Commit Graph

102 Commits

Author SHA1 Message Date
Brian Curtin a939105a40 Fix #15567. collections.deque wasn't imported 2012-08-09 23:04:42 -05:00
Antoine Pitrou 52849bfaa3 Issue #14308: Fix an exception when a "dummy" thread is in the threading module's active list after a fork(). 2012-04-19 23:55:01 +02:00
Benjamin Peterson 0013783d2f remove unused import 2012-02-03 19:07:30 -05:00
Charles-François Natali 41616300b1 Issue #11870: threading: Properly reinitialize threads internal locks and
condition variables to avoid deadlocks in child processes.
2011-12-18 18:22:24 +01:00
Gregory P. Smith c87620286d backport fix from r87741 related to the issue6643 fix in r87727. 2011-01-04 18:43:54 +00:00
Gregory P. Smith 2b79a81461 Merged revisions 87710 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r87710 | gregory.p.smith | 2011-01-03 13:06:12 -0800 (Mon, 03 Jan 2011) | 4 lines

  issue6643 - Two locks held within the threading module on each thread instance
  needed to be reinitialized after fork().  Adds tests to confirm that they are
  and that a potential deadlock and crasher bug are fixed (platform dependant).
........

This required a bit more fiddling for 2.x as __block and __started are __
private as well as the __started Event's __cond.  A new "private"
_reset_internal_locks() method is added to Thread and _Event objects to
address this.
2011-01-04 01:10:08 +00:00
Antoine Pitrou 47900cfa73 Merged revisions 87341 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r87341 | antoine.pitrou | 2010-12-17 18:42:16 +0100 (ven., 17 déc. 2010) | 4 lines

  Issue #4188: Avoid creating dummy thread objects when logging operations
  from the threading module (with the internal verbose flag activated).
........
2010-12-17 17:45:12 +00:00
Senthil Kumaran b02b311592 Fix Issue8262 - changing RuntimeError wording to "Threads can only be started once" 2010-04-06 03:23:33 +00:00
Gregory P. Smith 613c7a549a Issue #7481: When a threading.Thread failed to start it would leave the
instance stuck in initial state and present in threading.enumerate().
2010-02-28 18:36:09 +00:00
Georg Brandl 84fedf7f06 No need to assign the results of expressions used only for side effects. 2010-02-06 22:59:15 +00:00
Antoine Pitrou d7158d4c62 Issue #7282: Fix a memory leak when an RLock was used in a thread other
than those started through `threading.Thread` (for example, using
`thread.start_new_thread()`.
2009-11-09 16:00:11 +00:00
Antoine Pitrou 99c160b559 Issue #7264: Fix a possible deadlock when deallocating thread-local objects
which are part of a reference cycle.
2009-11-05 13:42:29 +00:00
Georg Brandl e1254d748d #7125: fix typo. 2009-10-14 15:51:48 +00:00
Benjamin Peterson d906ea62c8 fix Thread.ident when it is the main thread or a dummy thread #5632 2009-03-31 21:34:42 +00:00
Benjamin Peterson bd9dd31abd take the usual lock precautions around _active_limbo_lock 2009-03-31 21:06:30 +00:00
Georg Brandl ef660e8e50 #1674032: return value of flag from Event.wait(). OKed by Guido. 2009-03-31 20:41:08 +00:00
Antoine Pitrou 9fb1aca5d8 Backport relevant part of r66274 (in issue #874900). 2008-09-06 23:04:32 +00:00
Benjamin Peterson 973e6c2cf3 remove py3k warnings about the threading api; update docs
Reviewer: Benjamin Peterson
2008-09-01 23:12:58 +00:00
Benjamin Peterson b6a955672f fix a few get_name() calls and turn then to .name
Reviewer: Christian Heimes
2008-08-22 20:43:48 +00:00
Benjamin Peterson 6ee1a31e9b add py3k warnings for old threading APIs
they will still live in 3.0 but it can't hurt
2008-08-18 21:53:29 +00:00
Benjamin Peterson d810626f99 bring back the old API 2008-08-18 18:13:17 +00:00
Benjamin Peterson cbae869759 backport threading property changes 2008-08-18 17:45:09 +00:00
Benjamin Peterson d8a8972ca9 change threading.getIdent to a property
This is new in 2.6 so now need to worry about backwards compatibility :)
2008-08-18 16:40:03 +00:00
Brett Cannon 2005050152 Remove a tuple unpacking in a parameter list to suppress the SyntaxWarning with
-3.
2008-08-02 03:13:46 +00:00
Jesse Noller 5e62ca4fea Apply patch for 874900: threading module can deadlock after fork 2008-07-16 20:03:47 +00:00
Benjamin Peterson 13f7382e0d add old names back into __all__ 2008-06-11 18:02:31 +00:00
Benjamin Peterson f439560265 add aliases to threading module 2008-06-11 17:50:00 +00:00
Benjamin Peterson 0fbcf69455 give the threading API PEP 8 names 2008-06-11 17:27:50 +00:00
Gregory P. Smith 8856ddae25 Adds a Thread.getIdent() method to provide the _get_ident() value for
any given threading.Thread object.  feature request issue 2871.
2008-06-01 23:48:47 +00:00
Amaury Forgeot d'Arc d7a265129c #1733757: the interpreter would hang on shutdown, if the function set by sys.settrace
calls threading.currentThread.

The correction somewhat improves the code, but it was close.
Many thanks to the "with" construct, which turns python code into C calls.

I wonder if it is not better to sys.settrace(None) just after
running the __main__ module and before finalization.
2008-04-03 23:07:55 +00:00
Jeffrey Yasskin 105f3d4fdc Block the sys.exc_clear -3 warning from threading.py. 2008-03-31 00:35:53 +00:00
Amaury Forgeot d'Arc 504a48f90a Revert my experiment. I found one reason of failures in test_logging. 2008-03-29 01:41:08 +00:00
Amaury Forgeot d'Arc 554d4f0c13 At least let the module compile 2008-03-29 00:49:07 +00:00
Amaury Forgeot d'Arc 8a69707b80 Try to understand why most buildbots suddenly turned to red.
Undo the only change that might have unexpected effects.

To be followed.
2008-03-29 00:44:58 +00:00
Jeffrey Yasskin 8b9091fba0 Kill a race in test_threading in which the exception info in a thread finishing
up after it was joined had a traceback pointing to that thread's (deleted)
target attribute, while the test was trying to check that the target was
destroyed. Big thanks to Antoine Pitrou for diagnosing the race and pointing
out sys.exc_clear() to kill the exception early. This fixes issue 2496.
2008-03-28 04:11:18 +00:00
Jeffrey Yasskin 69e1309fd4 Thread.start() used sleep(0.000001) to make sure it didn't return before the
new thread had started. At least on my MacBook Pro, that wound up sleeping for
a full 10ms (probably 1 jiffy). By using an Event instead, we can be absolutely
certain that the thread has started, and return more quickly (217us).

Before:
$  ./python.exe -m timeit -s 'from threading import Thread'  't = Thread(); t.start(); t.join()'
100 loops, best of 3: 10.3 msec per loop
$  ./python.exe -m timeit -s 'from threading import Thread; t = Thread()'  't.isAlive()'
1000000 loops, best of 3: 0.47 usec per loop

After:
$  ./python.exe -m timeit -s 'from threading import Thread'  't = Thread(); t.start(); t.join()'
1000 loops, best of 3: 217 usec per loop
$  ./python.exe -m timeit -s 'from threading import Thread; t = Thread()'  't.isAlive()'
1000000 loops, best of 3: 0.86 usec per loop

To be fair, the 10ms isn't CPU time, and other threads including the spawned
one get to run during it. There are also some slightly more complicated ways to
get back the .4us in isAlive() if we want.
2008-02-28 06:09:19 +00:00
Jeffrey Yasskin a885c1521a Followup to r61011: Also avoid the reference cycle when the Thread's target
raises an exception.
2008-02-23 20:40:35 +00:00
Jeffrey Yasskin 3414ea9ed9 Prevent classes like:
class RunSelfFunction(object):
        def __init__(self):
            self.thread = threading.Thread(target=self._run)
            self.thread.start()
        def _run(self):
            pass
from creating a permanent cycle between the object and the thread by having the
Thread delete its references to the object when it completes.

As an example of the effect of this bug, paramiko.Transport inherits from
Thread to avoid it.
2008-02-23 19:40:54 +00:00
Raymond Hettinger 70ec29d0f4 Revert 60189 and restore performance. 2008-01-24 18:12:23 +00:00
Gregory P. Smith 95cd5c0b72 - Fix Issue #1703448: A joined thread could show up in the
threading.enumerate() list after the join() for a brief period until
  it actually exited.
2008-01-22 01:20:42 +00:00
Gregory P. Smith 64c5677de4 Replace spam.acquire() try: ... finally: spam.release() with "with spam:" 2008-01-22 01:12:02 +00:00
Guido van Rossum 54ec61ea6e Add a hack (originally devised in a slightly different form by Thomas Wouters)
to prevent spurious tracebacks when a daemon thread's cleanup happens to wake
up when the world around it has already been destroyed.
2007-08-20 15:18:04 +00:00
Nick Coghlan f8bbaa962f Eliminate RLock race condition reported in SF bug #1764059 2007-07-31 13:38:01 +00:00
Collin Winter 50b79ce8e6 Patch #1731049: make threading.py use a proper "raise" when checking internal state, rather than assert statements (which get stripped out by -O). 2007-06-06 00:17:35 +00:00
Martin v. Löwis 7b7c9d4208 Bug #1566280: Explicitly invoke threading._shutdown from Py_Main,
to avoid relying on atexit.
Will backport to 2.5.
2007-01-04 21:06:12 +00:00
Andrew MacIntyre 9291332de1 Patch #1454481: Make thread stack size runtime tunable.
Heavily revised, comprising revisions:
46640 - original trunk revision (backed out in r46655)
46647 - markup fix (backed out in r46655)
46692:46918 merged from branch aimacintyre-sf1454481

branch tested on buildbots (Windows buildbots had problems
not related to these changes).
2006-06-13 15:04:24 +00:00
Tim Peters 28eeefe566 Revert revisions:
46640 Patch #1454481:  Make thread stack size runtime tunable.
46647 Markup fix

The first is causing many buildbots to fail test runs, and there
are multiple causes with seemingly no immediate prospects for
repairing them.  See python-dev discussion.

Note that a branch can (and should) be created for resolving these
problems, like

svn copy svn+ssh://svn.python.org/python/trunk -r46640 svn+ssh://svn.python.org/python/branches/NEW_BRANCH

followed by merging rev 46647 to the new branch.
2006-06-04 23:52:47 +00:00
Andrew MacIntyre 6539d2d3c7 Patch #1454481: Make thread stack size runtime tunable. 2006-06-04 12:31:09 +00:00
Guido van Rossum da5b701aee Get rid of __context__, per the latest changes to PEP 343 and python-dev
discussion.
There are two places of documentation that still mention __context__:
Doc/lib/libstdtypes.tex -- I wasn't quite sure how to rewrite that without
spending a whole lot of time thinking about it; and whatsnew, which Andrew
usually likes to change himself.
2006-05-02 19:47:52 +00:00
Guido van Rossum 8f56d02309 Implement MvL's improvement on __context__ in Condition;
this can just call __context__ on the underlying lock.
(The same change for Semaphore does *not* work!)
2006-04-25 20:12:45 +00:00