Thread._stop() behavior changed in Python 3.4

F

Felix Yan

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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)

iQIcBAABAgAGBQJTJy5JAAoJEHhsY/Mw18uSzlwQAIxd+26D09Eez201Gm6sCf4e
47ToX++/FrvCqmGF/x8VTeglVm8pJLw89uGDsx9EB6jGkQgXoefGEYZhgCxlP3vH
3W7EL3yBjLjlYidMf99jjN+5k5nx/ypmyOfOnCUMPdbr7to/Za9z+NwPvhdimBcO
c5bqxx/j175/0rAnlPqHmelzZgtlC2nsvk5MT4ssm5LGfA1NsEJ5RCdm7+buKRRK
b9Ck3xKgElbYKRTa2nam2g57XESYG7DMW2E2VR168w/rIsRoQqbrzHWjj5USjQo0
+fmN4YjTRA+HbhF+UkpAiRNAuo1/3AKpCMMgJq/jlBDFjBO6Q3wpT9uMFcStK8J0
4XtpgF2kygHqbv+bwUV8itz+WBmzwZyPYeRaOelCh+j5V1FLaY/xChS9RfkYjcwv
NK7ghLzK6cO6w3Ahi+V0Hwy87/Y8+TlKPpry5gWwdWRCa4U96SWaDmawyAztxh3N
3mezW19nb+/Yk2ppu1nTTuEJuPjJ4EMhjy7FkdiuhPbZ3bxhg4QYwWQOOfrF9clI
OQDq78n6vtwQEdRhaQ0SzP1mvhKS/QZ2oN8RSGcVQkFyqRU38roVq6Q5VESCNihE
1R1QaDXI3N35wO7HJ10bnvYPsWXi1N8u8AHjo2vysGNW/HRBVY4kIC9AbQnKovJq
vaw29g4qO/MVMCEyIKvY
=BhNs
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,955
Messages
2,570,117
Members
46,705
Latest member
v_darius

Latest Threads

Top