Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gevent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gevent
Commits
83ba5093
Commit
83ba5093
authored
Jan 07, 2012
by
Denis Bilenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add examples/multiple_threads.py
parent
e018c0bc
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
0 deletions
+44
-0
examples/multiple_threads.py
examples/multiple_threads.py
+44
-0
No files found.
examples/multiple_threads.py
0 → 100644
View file @
83ba5093
import
sys
import
gevent
from
gevent
import
monkey
start_new_thread
=
monkey
.
get_unpatched
(
'thread'
,
'start_new_thread'
)
def
_run
(
func
,
args
,
kwargs
,
async
,
result
):
try
:
value
=
func
(
*
args
,
**
kwargs
)
result
.
append
((
True
,
value
))
except
:
result
.
append
((
False
,
sys
.
exc_info
()))
finally
:
async
.
send
()
def
_run_in_thread
(
func
,
*
args
,
**
kwargs
):
hub
=
gevent
.
get_hub
()
async
=
hub
.
loop
.
async
()
result
=
[]
start_new_thread
(
_run
,
(
func
,
args
,
kwargs
,
async
,
result
))
hub
.
wait
(
async
)
return
result
[
0
]
def
run_in_thread
(
func
,
*
args
,
**
kwargs
):
succeeded
,
result
=
_run_in_thread
(
func
,
*
args
,
**
kwargs
)
if
succeeded
:
return
result
else
:
raise
result
if
__name__
==
'__main__'
:
import
os
import
time
start
=
time
.
time
()
for
_
in
xrange
(
4
):
gevent
.
spawn
(
run_in_thread
,
os
.
system
,
'sleep 1'
)
gevent
.
run
()
delay
=
time
.
time
()
-
start
print
'Running "sleep 1" 4 threads. Should take about a second: %.2fs'
%
delay
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment