Created
May 25, 2012 10:29
-
-
Save Bluehorn/2787191 to your computer and use it in GitHub Desktop.
An example of how Thread._Thread__stop() does not stop a thread
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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