-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththread_py2.py
More file actions
38 lines (26 loc) · 826 Bytes
/
Copy paththread_py2.py
File metadata and controls
38 lines (26 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/python3
# coding=UTF-8
#================================================================
# Copyright (C) 2018 HALO Ltd. All rights reserved.
#
# 文件名称:thread_py2.py
# 创 建 者:Zhangdunfeng
# 创建日期:2018-11-23 09:05:23
# 描 述:_thread python2的线程处理模块,python3已废弃,不过可以兼容
#
#================================================================
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: 无法启动线程")
while 1:
pass