Last active
August 19, 2016 13:49
-
-
Save mebusw/748fbcc4de0a5f4ce5a0 to your computer and use it in GitHub Desktop.
simple way of multi-threading in python
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
#coding=utf-8 | |
#!/usr/bin/python | |
import thread | |
import time | |
# 为线程定义一个函数 | |
def print_time( threadName, delay): | |
count = 0 | |
while count < 5: | |
time.sleep(delay) | |
count += 1 | |
print "%s: %s" % ( threadName, time.ctime(time.time()) ) | |
# 创建两个线程 | |
try: | |
thread.start_new_thread( print_time, ("Thread-1", 2, ) ) | |
thread.start_new_thread( print_time, ("Thread-2", 4, ) ) | |
except: | |
print "Error: unable to start thread" | |
while 1: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment