#!/usr/bin/python
# -*- coding: UTF-8 -*- 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
相关文章
- 【LeetCode】337. House Robber III 解题报告(Python)
- 【转载】不得不知道的Python字符串编码相关的知识
- Python字符串和编码
- python 应用 base64、hmac、hashlib包实现:MD5编码 base64编码解码、SHA256编码、urlsafe_b64encode编码等等基本所有的加密签名的方法
- virtualenv 运行python 解决依赖冲突问题 尤其是django那种蛋疼的版本问题
- python练习题-day21
- python设计模式第九天【策略模式】
- python之获取微信access_token
- Python基础——判断和循环
- python拼接