#!/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
相关文章
- 使用python绘制桑基图
- 【Python】解决Python报错:IndexError: list index out of range
- Python3.x:将数据下载到xls时候用xml格式保存一份读取内容
- 【LeetCode】940. Distinct Subsequences II 解题报告(Python)
- 使用Matplotlib进行Python绘图
- 【LeetCode】115. Distinct Subsequences 解题报告(Python)
- Ruby语言与Python:深度比较与独特魅力探索
- [Python]循环嵌套nested loop-练习题
- Linux 安装Python37
- Python怎么循环计数:深入解析与实践