Thread._stop() behavior changed in Python 3.4

Felix Yan felixonmars at gmail.com
Mon Mar 17 18:18:01 CET 2014


Hi list,

I noticed a behavior change on Thread._stop() with Python 3.4.

I know the method is an undocumented "feature" itself, but some projects are 
using it, and now they fail.

A minimized snippet to reproduce:

#!/usr/bin/python
import threading
def stale():
    import time
    time.sleep(1000)
t = threading.Thread(target=stale)
t.start()
t._stop()

This works correctly with Python 3.3, the program exits immediately after 
t._stop() called, and no exception was raised.

But with Python 3.4, an AssertionError was raised:

Traceback (most recent call last):
  File "test.py", line 8, in <module>
    t._stop()
  File "/usr/lib/python3.4/threading.py", line 990, in _stop
    assert not lock.locked()
AssertionError

And the program still waits on the sleep().

I know trying to forcefully stop a thread is not really a good practice, but I 
still wonder if there's an easy way to get broken programs to work again, just 
in the way they currently are?

Downstream bug reports, for reference:

http://youtrack.jetbrains.com/issue/PY-12317
https://github.com/paramiko/paramiko/issues/286

Regards,
Felix Yan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.python.org/pipermail/python-list/attachments/20140318/f09adf6a/attachment.sig>


More information about the Python-list mailing list