Skip to content

Instantly share code, notes, and snippets.

@mebusw
Last active August 19, 2016 13:49
Show Gist options
  • Save mebusw/748fbcc4de0a5f4ce5a0 to your computer and use it in GitHub Desktop.
Save mebusw/748fbcc4de0a5f4ce5a0 to your computer and use it in GitHub Desktop.
simple way of multi-threading in python
#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