FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-1/threading_test.py at master · jayronjiang/python-1 · GitHub
jayronjiang
/
python-1
Public
forked from
zhanghe06/python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
python-1
/
threading_test.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
44 lines (37 loc) · 1.13 KB
Breadcrumbs
python-1
/
threading_test.py
Copy path
File metadata and controls
44 lines (37 loc) · 1.13 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
33
34
35
36
37
38
39
40
41
42
43
44
# encoding: utf-8
__author__
=
'zhanghe'
import
time
import
threading
def
loop
():
"""
新线程执行的代码
:return:
"""
print
'thread %s is running...'
%
threading
.
current_thread
().
name
n
=
0
while
n
<
5
:
n
+=
1
print
'thread %s >>> %s'
%
(
threading
.
current_thread
().
name
,
n
)
time
.
sleep
(
1
)
print
'thread %s ended.'
%
threading
.
current_thread
().
name
if
__name__
==
'__main__'
:
# 多线程实例 启动一个线程就是把一个函数传入并创建Thread实例,然后调用start()开始执行
print
time
.
ctime
()
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
print
time
.
ctime
()
# 运行结果:
# Mon Apr 27 23:04:31 2015
# thread MainThread is running...
# thread LoopThread is running...
# thread LoopThread >>> 1
# thread LoopThread >>> 2
# thread LoopThread >>> 3
# thread LoopThread >>> 4
# thread LoopThread >>> 5
# thread LoopThread ended.
# thread MainThread ended.
# Mon Apr 27 23:04:36 2015
Back
|
FazBrowse Home
|
New Git URL