Commit Graph

189 Commits

Author SHA1 Message Date
Victor Stinner cd590a7ced
bpo-1230540: Add threading.excepthook() (GH-13515)
Add a new threading.excepthook() function which handles uncaught
Thread.run() exception. It can be overridden to control how uncaught
exceptions are handled.

threading.ExceptHookArgs is not documented on purpose: it should not
be used directly.

* threading.excepthook() and threading.ExceptHookArgs.
* Add _PyErr_Display(): similar to PyErr_Display(), but accept a
  'file' parameter.
* Add _thread._excepthook(): C implementation of the exception hook
  calling _PyErr_Display().
* Add _thread._ExceptHookArgs: structseq type.
* Add threading._invoke_excepthook_wrapper() which handles the gory
  details to ensure that everything remains alive during Python
  shutdown.
* Add unit tests.
2019-05-28 00:39:52 +02:00
Jake Tesler b121f63155 bpo-36084: Add native thread ID (TID) to threading.Thread (GH-13463)
Add native thread ID (TID) to threading.Thread objects
(supported platforms: Windows, FreeBSD, Linux, macOS).
2019-05-22 17:43:16 +02:00
Victor Stinner d12e75734d
Revert "bpo-36084: Add native thread ID to threading.Thread objects (GH-11993)" (GH-13458)
This reverts commit 4959c33d25.
2019-05-21 12:44:57 +02:00
Jake Tesler 4959c33d25 bpo-36084: Add native thread ID to threading.Thread objects (GH-11993) 2019-05-12 19:08:24 +02:00
Carl Bordum Hansen 62fa51f121 Fix typos and improve grammar in threading.Barrier docstrings (GH-12210) 2019-03-09 09:38:05 -08:00
Dong-hee Na 36d9e9a4d5 bpo-35283: Update the docstring of threading.Thread.join method (GH-11596) 2019-01-18 10:50:47 +01:00
Dong-hee Na 89669ffe10 bpo-35283: Add deprecation warning for Thread.isAlive (GH-11454)
Add a deprecated warning for the threading.Thread.isAlive() method.
2019-01-17 13:14:45 +01:00
Skip Montanaro 5634331a76 bpo-33556: Remove reference to thread module from docstring (GH-6963) 2018-05-18 13:38:36 -05:00
Antoine Pitrou 1023dbbcb7 bpo-31516: current_thread() should not return a dummy thread at shutdown (#3673)
bpo-31516: current_thread() should not return a dummy thread at shutdown
2017-10-02 16:42:15 +02:00
Antoine Pitrou a6a4dc816d bpo-31370: Remove support for threads-less builds (#3385)
* Remove Setup.config
* Always define WITH_THREAD for compatibility.
2017-09-07 18:56:24 +02:00
Antoine Pitrou ee84a60858 bpo-18966: non-daemonic threads created by a multiprocessing.Process should be joined on exit (#3111)
* bpo-18966: non-daemonic threads created by a multiprocessing.Process should be joined on exit

* Add NEWS blurb
2017-08-16 20:53:28 +02:00
Gregory P. Smith 163468a766 bpo-16500: Don't use string constants for os.register_at_fork() behavior (#1834)
Instead use keyword only arguments to os.register_at_fork for each of the scenarios.
Updates the documentation for clarity.
2017-05-29 10:03:41 -07:00
Antoine Pitrou 4a8bcdf79c bpo-16500: Use register_at_fork() in the threading module (#1843)
* bpo-16500: Use register_at_fork() in the threading module

* Update comment at top of _after_fork()
2017-05-28 14:02:26 +02:00
Antoine Pitrou f7ecfac0c1 Doc nits for bpo-16500 (#1841)
* Doc nits for bpo-16500

* Fix more references
2017-05-28 11:35:14 +02:00
Serhiy Storchaka aefa7ebf0f bpo-6532: Make the thread id an unsigned integer. (#781)
* bpo-6532: Make the thread id an unsigned integer.

From C API side the type of results of PyThread_start_new_thread() and
PyThread_get_thread_ident(), the id parameter of
PyThreadState_SetAsyncExc(), and the thread_id field of PyThreadState
changed from "long" to "unsigned long".

* Restore a check in thread_get_ident().
2017-03-23 14:48:39 +01:00
Xiang Zhang f3a9faba4b bpo-29376: Fix assertion error in threading._DummyThread.is_alive() (GH-236) 2017-02-27 11:01:30 +08:00
Martin Panter 02b75abf73 Merge spelling and grammar fixes from 3.5 2016-08-05 01:51:39 +00:00
Martin Panter 69332c1a64 Fix spelling and grammar in documentation and code comments 2016-08-04 13:07:31 +00:00
Martin Panter 3e04d5b306 Issue #27076: Merge spelling from 3.5 2016-05-26 06:03:19 +00:00
Martin Panter 46f50726a0 Issue #27076: Doc, comment and tests spelling fixes
Most fixes to Doc/ and Lib/ directories by Ville Skyttä.
2016-05-26 05:35:26 +00:00
Zachary Ware e7041fa215 Closes #26987: Merge with 3.5 2016-05-09 14:50:36 -05:00
Zachary Ware 78b5ed98d8 Issue #26987: Correct implementation to match comment
This was inadvertently changed in 644b677c2ae5 to use self._stderr
instead of _sys.stderr.
2016-05-09 14:49:31 -05:00
Martin Panter 19e69c5a20 Issue #23883: Add missing APIs to __all__; patch by Jacek Kołodziej 2015-11-14 12:46:42 +00:00
Benjamin Peterson 062f4cec5e merge 3.4 (#25362) 2015-10-10 19:36:40 -07:00
Benjamin Peterson 414918a939 use the with statement for locking the internal condition (closes #25362)
Patch by Nir Soffer.
2015-10-10 19:34:46 -07:00
Benjamin Peterson 72181b2f53 merge 3.4 (#25319) 2015-10-05 22:00:33 -07:00
Benjamin Peterson 15982aad2b reinitialize an Event's Condition with a regular lock (closes #25319) 2015-10-05 21:56:22 -07:00
R David Murray f5387c0d6d Merge: #11866: Eliminate race condition in the computation of names for new threads. 2014-10-04 17:45:15 -04:00
R David Murray b186f1df41 #11866: Eliminate race condition in the computation of names for new threads.
Original patch by Peter Saveliev.
2014-10-04 17:43:54 -04:00
Serhiy Storchaka c904e87c13 Issue #22423: Unhandled exception in thread no longer causes unhandled
AttributeError when sys.stderr is None.
2014-09-21 22:09:20 +03:00
Serhiy Storchaka 52005c2e13 Issue #22423: Unhandled exception in thread no longer causes unhandled
AttributeError when sys.stderr is None.
2014-09-21 22:08:13 +03:00
Victor Stinner ae58649721 Issue #22043: time.monotonic() is now always available
threading.Lock.acquire(), threading.RLock.acquire() and socket operations now
use a monotonic clock, instead of the system clock, when a timeout is used.
2014-09-02 23:18:25 +02:00
Antoine Pitrou fa9211b11d Issue #22185: Fix an occasional RuntimeError in threading.Condition.wait() caused by mutation of the waiters queue without holding the lock.
Patch by Doug Zongker.
2014-08-29 23:27:33 +02:00
Antoine Pitrou a64b92edd3 Issue #22185: Fix an occasional RuntimeError in threading.Condition.wait() caused by mutation of the waiters queue without holding the lock.
Patch by Doug Zongker.
2014-08-29 23:26:36 +02:00
Raymond Hettinger 62f4dad816 Issue 21137: Better repr for threading.Lock() 2014-05-25 18:22:35 -07:00
Victor Stinner 7fa767e517 Issue #20976: pyflakes: Remove unused imports 2014-03-20 09:16:38 +01:00
Antoine Pitrou 1095907624 Remove stray semicolon 2014-03-17 18:22:41 +01:00
Tim Peters a577f1e0f1 Changed a comment to end grammar bikeshedding ;-) 2013-10-26 11:56:16 -05:00
Tim Peters 7bad39f174 Fiddled Thread.join() to be a little simpler. Kinda ;-) 2013-10-25 22:33:52 -05:00
Tim Peters e5bb0bf04d Issue #19399: fix sporadic test_subprocess failure.
Change Thread.join() with a negative timeout to just return.  The
behavior isn't documented then, but this restores previous
behavior.
2013-10-25 20:46:51 -05:00
Georg Brandl bb2ed516cc merge with 3.3 2013-10-13 10:44:04 +02:00
Georg Brandl c30b59fe3d Closes #17375: port new threading docstrings from 2.7. 2013-10-13 10:43:59 +02:00
Tim Peters e99bdb9694 Issue 19158: a rare race in BoundedSemaphore could allow .release() too often. 2013-10-08 21:12:58 -05:00
Tim Peters 7634e1cf90 Issue 19158: a rare race in BoundedSemaphore could allow .release() too often. 2013-10-08 20:55:51 -05:00
Tim Peters 72460fa68b Get "stopped" back into repr(Thread) when appropriate.
Due to recent changes, a Thread doesn't know that it's over before
someone calls .join() or .is_alive().  That meant repr(Thread)
continued to include "started" (and not "stopped") before one of
those methods was called, even if hours passed since the thread
ended.

Repaired that.
2013-09-09 18:48:24 -05:00
Tim Peters b5e9ac9ec6 Another stab at the thread cleanup patch.
Antoine Pitrou found a variation that worked for him on the
thread+fork tests, and added an important

    self._is_stopped = True

to the after-fork code.  I confess I don't know why things passed
before.  But then mixing fork with threads is insane ;-)
2013-09-09 14:41:50 -05:00
Tim Peters 7875523f16 Backed out changeset 1f5a7853680c
Unixy buildbots were failing the thread + fork tests :-(
2013-09-09 13:47:16 -05:00
Tim Peters 7a6054b19d Minor cleanup of the new scheme for detecting thread termination.
Documented some obscurities, and assert'ed ._stop()'s crucial precondition.
2013-09-09 12:57:10 -05:00
Tim Peters c363a23eff Issue 18984: Remove ._stopped Event from Thread internals.
The fix for issue 18808 left us checking two things to be sure a Thread
was done:  an Event (._stopped) and a mutex (._tstate_lock).  Clumsy &
brittle.  This patch removes the Event, leaving just a happy lock :-)

The bulk of the patch removes two excruciating tests, which were
verifying sanity of the internals of the ._stopped Event after a fork.
Thanks to Antoine Pitrou for verifying that's the only real value
these tests had.

One consequence of moving from an Event to a mutex:  waiters (threads
calling Thread.join()) used to block each on their own unique mutex
(internal to the ._stopped event), but now all contend on the same
mutex (._tstate_lock).  These approaches have different performance
characteristics on different platforms.  I don't think it matters in
this context.
2013-09-08 18:44:40 -05:00
Antoine Pitrou 5da7e7959e Issue #18808 again: fix the after-fork logic for not-yet-started or already-stopped threads.
(AFAICT, in theory, we must reset all the locks, not just those in use)
2013-09-08 13:19:06 +02:00