On Mon, Mar 17, 2014 at 11:40 AM, Chris Angelico <ros...@gmail.com> wrote:
> 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.

I was curious about that -- after all, Python's threads aren't truly
concurrent, so perhaps they could just test the flag each time they
resume -- so I tested it using 3.3.  First I tried simply adding a
print call on to the end of the OP's function:

>>> def stale():
...     import time
...     time.sleep(1000)
...     print('hello')
...
>>> t = threading.Thread(target=stale)
>>> t.start(); t._stop()

No output was printed, so at least a sleeping thread can apparently be
stopped.  Then I tried removing the sleep call:

>>> def stale():
...     for i in range(10): print('hello')
...
>>> t = threading.Thread(target=stale)
>>> t.start(); print('Starting'); t._stop(); print('Stopping')
hello
Starting
Stopping
>>> hello
hello
hello
hello
hello
hello
hello
hello
hello

So yes, despite the lack of true concurrency, a thread can continue to
run after its _stop has been called.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to