Skip to content

Instantly share code, notes, and snippets.

@Bluehorn
Created May 25, 2012 10:29
Show Gist options
  • Save Bluehorn/2787191 to your computer and use it in GitHub Desktop.
Save Bluehorn/2787191 to your computer and use it in GitHub Desktop.
An example of how Thread._Thread__stop() does not stop a thread
#! /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