Skip to content

Instantly share code, notes, and snippets.

@maplebeats
Last active December 13, 2015 19:49
Show Gist options
  • Save maplebeats/4965884 to your computer and use it in GitHub Desktop.
Save maplebeats/4965884 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import threading
from time import sleep
def wrong():
#Do sth.
print("wrong")
sleep(1)
a = threading.Thread(target=wrong)
a.start()
def right():
while True:
sth()
def right2():
c = threading.Thread(target=sth2)
c.setDaemon(True)
c.start()
print("join")
c.join()
def sth2():
while True:
print("sth2")
sleep(1)
#Do sth
pass
def sth():
print("sth")
#Do sth
sleep(1)
pass
def test1():
try:
wrong()
except KeyboardInterrupt:
print("success")
def test2():
try:
right()
except KeyboardInterrupt:
print("success")
def test3():
try:
right2()
except KeyboardInterrupt:
print("success")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment