Commit Graph

39 Commits

Author SHA1 Message Date
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 002533013f Kill a small potential leak in test_threading.
The leak may not manifest itself if the OS re-uses the same thread ids
(I suppose Neal's machine doesn't :-))
2009-11-08 00:24:12 +00:00
Antoine Pitrou c98efe0500 Issue #7270: Add some dedicated unit tests for multi-thread synchronization
primitives such as Lock, RLock, Condition, Event and Semaphore.
2009-11-06 22:34:35 +00:00
Antoine Pitrou bb0bb30acc Suppress transient refleaks in test_threading. 2009-10-27 20:02:23 +00:00
Antoine Pitrou b119ca9df4 Fix Windows buildbot failure 2009-10-23 12:01:13 +00:00
Antoine Pitrou 9bd246bba9 Test wouldn't work in debug mode.
We probably need a function in test_support to handle this.
2009-10-20 21:59:25 +00:00
Antoine Pitrou efb60c0ceb Issue #1722344: threading._shutdown() is now called in Py_Finalize(), which
fixes the problem of some exceptions being thrown at shutdown when the
interpreter is killed. Patch by Adam Olsen.
2009-10-20 21:29:37 +00:00
Antoine Pitrou 603acf99d0 Add a comment about unreachable code, and fix a typo 2009-10-18 18:37:11 +00:00
Antoine Pitrou 8a172b14a3 Add a test for same-thread asynchronous exceptions (see #1779233). 2009-10-18 18:22:04 +00:00
Benjamin Peterson 5c8da86f3a convert usage of fail* to assert* 2009-06-30 22:57:08 +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
Georg Brandl ef660e8e50 #1674032: return value of flag from Event.wait(). OKed by Guido. 2009-03-31 20:41:08 +00:00
Gregory P. Smith 0806749e63 Works around issue3863: freebsd4/5/6 and os2emx are known to have OS bugs when
calling fork() from a child thread.  This disables that unit test (with a note
printed to stderr) on those platforms.

A caveat about buggy platforms is added to the os.fork documentation.
2008-09-30 20:41:13 +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
Benjamin Peterson f5668f13c8 try to fix test_threading on the Windows bot 2008-07-17 12:57:22 +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 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 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 510eab5965 Speed test_threading up from 14s to .5s, and avoid a deadlock on certain
failures. The test for enumerate-after-join is now a little less rigorous, but
the bug it references says the error happened in the first couple iterations,
so 100 iterations should still be enough.

cProfile was useful for identifying the slow tests here.
2008-03-21 18:48:04 +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
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
Amaury Forgeot d'Arc 025c347d61 Issue #1402: PyInterpreterState_Clear() may still invoke user code
(in deallocation of running threads, for example), so the PyGILState_Release()
function must still be functional.
On the other hand, _PyGILState_Fini() only frees memory, and can be called later.

Backport candidate, but only after some experts comment on it.
2007-11-29 23:35:25 +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
Tim Peters 08574770c5 test_PyThreadState_SetAsyncExc(): This is failing on some
64-bit boxes.  I have no idea what the ctypes docs mean
by "integers", and blind-guessing here that it intended to
mean the signed C "int" type, in which case perhaps I can
repair this by feeding the thread id argument to type
ctypes.c_long().

Also made the worker thread daemonic, so it doesn't hang
Python shutdown if the test continues to fail.
2006-08-11 00:49:01 +00:00
Tim Peters 4643c2fda1 Followup to bug #1069160.
PyThreadState_SetAsyncExc():  internal correctness changes wrt
refcount safety and deadlock avoidance.  Also added a basic test
case (relying on ctypes) and repaired the docs.
2006-08-10 22:45:34 +00:00
Andrew MacIntyre 16ee33adfc test_threading now skips testing alternate thread stack sizes on
platforms that don't support changing thread stack size.
2006-08-06 12:37:03 +00:00
Andrew MacIntyre 93e3ecb1f4 Increase the small thread stack size to get the test
to pass reliably on the one buildbot that insists on
more than 32kB of thread stack.
2006-06-13 19:02:35 +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
Tim Peters 711906e0c2 threading._DummyThread.__init__(): document obscure new code.
test_threading.test_foreign_thread():  new test does a basic check that
"foreign" threads can using the threading module, and that they create
a _DummyThread instance in at least one use case.  This isn't a very
good test, since a thread created by thread.start_new_thread() isn't
particularly "foreign".
2005-01-08 07:30:42 +00:00
Tim Peters 84d548994e Converted to a unittest. Added checks that the bounded semaphore actually
does what it's supposed to do.
2005-01-08 06:03:17 +00:00
Barry Warsaw 04f357cffe Get rid of relative imports in all unittests. Now anything that
imports e.g. test_support must do so using an absolute package name
such as "import test.test_support" or "from test import test_support".

This also updates the README in Lib/test, and gets rid of the
duplicate data dirctory in Lib/test/data (replaced by
Lib/email/test/data).

Now Tim and Jack can have at it. :)
2002-07-23 19:04:11 +00:00
Tim Peters 02035bc68d Test failed because these was no expected-output file, but always printed
to stdout.  Repaired by not printing at all except in verbose mode.

Made the test about 6x faster -- envelope analysis showed it took time
proportional to the square of the # of tasks.  Now it's linear.
2001-08-20 21:45:19 +00:00
Skip Montanaro 4533f60da5 add a few test cases for threading module. 2001-08-20 20:28:48 +00:00