Thread._stop() behavior changed in Python 3.4
rosuav at gmail.com
Mon Mar 17 18:40:51 CET 2014
On Tue, Mar 18, 2014 at 4:18 AM, Felix Yan <felixonmars at gmail.com> wrote:
> 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.
> 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?
You're using something that has a leading underscore on the name.
Frankly, you shouldn't be doing that. Your code was already broken,
before 3.4 came along, and it's just that 3.4 highlighted that
brokenness. The PyCharm report that this is a Python 3.4 bug is simply
incorrect. This code should be a strong indication that something's
reaching into places it shouldn't be:
The solution is to have the thread acknowledge, in some way, that it
needs to shut down. Forcefully stopping a thread is actually a really
bad practice, at least in Python (with OS/2 and VX-REXX, it's a
different matter). Antoine says that this doesn't even stop the thread
(I can't say; I've never used _stop(), for obvious reasons), so this
code was doubly broken. The change in 3.4 should be an excuse to fix
the code so it actually works, and works according to the spec, which
will mean it works on all versions.
More information about the Python-list