Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

An example of how Thread._Thread__stop() does not stop a thread

View thread_stop_fail.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#! /usr/bin/python
 
import time
import threading
 
def f():
for x in range(10):
print "I am alive and running"
time.sleep(0.1)
 
 
thread = threading.Thread(target=f)
thread.start()
time.sleep(0.5)
print "Stopping the thread"
thread._Thread__stop()
print "Stopped the thread"
time.sleep(1)
 
 
# On my system this gives the following output:
# torsten@sharokan:~$ python demo.py
# I am alive and running
# I am alive and running
# I am alive and running
# I am alive and running
# I am alive and running
# Stopping the thread
# Stopped the thread
# I am alive and running
# I am alive and running
# I am alive and running
# I am alive and running
# I am alive and running
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.