- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultithread.py
More file actions
Latest commit
21 lines (18 loc) · 584 Bytes
/
Copy pathmultithread.py
File metadata and controls
21 lines (18 loc) · 584 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# /usr/bin/env python
# -*- utf-8 -*-
importthreading
importtime
# 新线程执行的代码:
defloop():
print('thread %s is running...'%threading.current_thread().name)
n=0
whilen<9:
n=n+1
print('thread %s >>> %s'% (threading.current_thread().name, n))
time.sleep(1)
print('thread %s ended.'%threading.current_thread().name)
print('thread %s is running...'%threading.current_thread().name)
t=threading.Thread(target=loop, name='LoopThread')
t.start()
t.join()
print('thread %s ended.'%threading.current_thread().name)