Last active
December 13, 2015 19:49
-
-
Save maplebeats/4965884 to your computer and use it in GitHub Desktop.
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/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