-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Thread shutdown exception in Thread.notify() #44981
Comments
Hi, I sometimes see the following exceptions when shutting down my app (using Python 2.5.1): Unhandled exception in thread started by
Error in sys.excepthook:
Original exception was:
Exception in thread Thread-3 (most likely raised during interpreter shutdown):
Traceback (most recent call last):
File "/usr/local/lib/python2.5/threading.py", line 460, in __bootstrap
File "/usr/local/lib/python2.5/threading.py", line 440, in run
File "/home/yang/local/armed/lib/python2.5/site-packages/afx/threads.py", line 71, in worker
File "/usr/local/lib/python2.5/Queue.py", line 176, in get
File "/usr/local/lib/python2.5/threading.py", line 248, in notify
<type 'exceptions.TypeError'>: exceptions must be classes, instances, or strings (deprecated), not NoneType
Unhandled exception in thread started by
Error in sys.excepthook:
Original exception was:
Exception in thread Thread-6 (most likely raised during interpreter shutdown):
Traceback (most recent call last):
File "/usr/local/lib/python2.5/threading.py", line 460, in __bootstrap
File "/usr/local/lib/python2.5/threading.py", line 440, in run
File "/home/yang/local/armed/lib/python2.5/site-packages/afx/threads.py", line 71, in worker
File "/usr/local/lib/python2.5/Queue.py", line 176, in get
File "/usr/local/lib/python2.5/threading.py", line 248, in notify
<type 'exceptions.TypeError'>: exceptions must be classes, instances, or strings (deprecated), not NoneType
Unhandled exception in thread started by
Error in sys.excepthook:
Original exception was: Here is the code from my application: def worker():
debug( 'starting worker' )
while True:
msg = i.get() # <-- THIS IS LINE 71
if msg is stop_msg: break
resultbuf, func, args, kwargs = msg
result, exc = None, None
try:
result = func( *args, **kwargs )
except:
t, v, tb = exc_info()
exc = t, v, tb.tb_next
o.put( ( resultbuf, result, exc ) )
s.send( 'x' ) # assuming socket.send is thread-safe
debug( 'stopping worker' ) Here is the origin of the exception (in threading.py): def notify(self, n=1):
assert self._is_owned(), "notify() of un-acquire()d lock" # <-- THIS IS LINE 248
__waiters = self.__waiters
waiters = __waiters[:n]
if not waiters:
if __debug__:
self._note("%s.notify(): no waiters", self)
return
self._note("%s.notify(): notifying %d waiter%s", self, n,
n!=1 and "s" or "")
for waiter in waiters:
waiter.release()
try:
__waiters.remove(waiter)
except ValueError:
pass I'm not sure why this is happening. The threads are not daemon threads; I terminate them cleanly. When I get a SIGINT (I usu. shut down my app with ctrl-C), I enqueue n stop_msg's to the 'i' Queue so that the n workers can all exit. Note I usually launch 5 workers, so I'm not consistently getting an exception per worker. Also, I've been unable to reproduce this at will. |
Do you join() the worker threads, waiting until they finish, before exiting the main thread? |
No, as they are not daemon threads. |
I'm getting the same kind of errors. It seems that python sets every variable to None, and then wakeup sleeping threads, which then crash, as they try to work with the None variables Exception in thread Thread-3 (most likely raised during interpreter shutdown):
Traceback (most recent call last):
File "/usr/lib/python2.4/threading.py", line 442, in __bootstrap
File "/home/thomas/Programmering/python/skak/0.7/lib/pychess/System/ThreadPool.py", line 49, in run
File "/usr/lib/python2.4/Queue.py", line 89, in put
File "/usr/lib/python2.4/threading.py", line 237, in notify
exceptions.TypeError: exceptions must be classes, instances, or strings (deprecated), not NoneType
Unhandled exception in thread started by
Error in sys.excepthook |
I see the same problem. I'm not sure my code is clean, I've traced my code with print statements, As a result, these threads don't terminate on time, |
Though these exceptions while shutting down are mostly harmless, they |
I think the general idea of the problem has been stated, but I figured I This is not about to change since this occurs because of coding |
Py_Main calls WaitForThreadShutdown before calling Py_Finalize, which However, if SystemExit is raised (such as via sys.exit()), Py_Exit is Can someone who's experienced this bug check if they're using |
To put it another way: SystemExit turns non-daemon threads into daemon |
Hold on, why is that wrong? What if the threads block forever, |
I disagree. sys.exit() attempts to gracefully shutdown the interpreter, Note that, as python doesn't call a main function, you have to use |
OK, I will re-open to see if some other core developer wants to take |
|
No, it means you have to be careful if you do. Shutting down properly |
This bug was introduced by r53249, which was fixing bug bpo-1566280. Fixed by moving the WaitForThreadShutdown call into Py_Finalize, so all Martin, since you did the previous fix, can you review this one? |
Oh, and the patch includes a testcase. The current test_threading.py |
The patch looks good to me. |
Nope, no access. |
Ok, I'll do it then! |
Patch was committed in trunk, py3k and 3.1. Waiting for 2.6 to be |
Backported to 2.6 in r75749. |
Any idea if there is a nightly build for Python 2.6? The latest release was 2.6.4 and was 2 days before submitting the patch. Or the only alternative is to build it myself? Any ideas on when we could see 2.6.5? - I tried to look for a release timeline but I wasn't able to locate one. |
I have seen somewhere (ask google), that python 2.6.5 would be released mid-march. |
According to Barry's latest email on the subject, the dates are: 2009-03-01 Python 2.6.5 rc 1 And no, there are no nightly builds, you have to build it yourself, I'm afraid. |
Looks like this influenced mod_wsgi as well: http://groups.google.com/group/modwsgi/browse_thread/thread/ba82b2643564d2dd |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: