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
cb9e7f63
Commit
cb9e7f63
authored
Aug 18, 2009
by
Denis Bilenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add gevent.spawn_raw; remove rawgreenlet.spawn and rawgreenlet.spawn_later
parent
75da912c
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
37 additions
and
47 deletions
+37
-47
gevent/__init__.py
gevent/__init__.py
+2
-1
gevent/coros.py
gevent/coros.py
+5
-6
gevent/hub.py
gevent/hub.py
+17
-0
gevent/proc.py
gevent/proc.py
+2
-2
gevent/rawgreenlet.py
gevent/rawgreenlet.py
+7
-32
gevent/socket.py
gevent/socket.py
+2
-3
gevent/thread.py
gevent/thread.py
+2
-3
No files found.
gevent/__init__.py
View file @
cb9e7f63
...
...
@@ -8,6 +8,7 @@ __all__ = ['Greenlet',
'spawn_link'
,
'spawn_link_value'
,
'spawn_link_exception'
,
'spawn_raw'
,
'joinall'
,
'killall'
,
'Timeout'
,
...
...
@@ -29,7 +30,7 @@ spawn_link = Greenlet.spawn_link
spawn_link_value
=
Greenlet
.
spawn_link_value
spawn_link_exception
=
Greenlet
.
spawn_link_exception
from
gevent.timeout
import
Timeout
,
with_timeout
from
gevent.hub
import
getcurrent
,
GreenletExit
,
sleep
,
kill
,
signal
,
shutdown
from
gevent.hub
import
getcurrent
,
GreenletExit
,
s
pawn_raw
,
s
leep
,
kill
,
signal
,
shutdown
try
:
from
gevent.hub
import
fork
except
ImportError
:
...
...
gevent/coros.py
View file @
cb9e7f63
...
...
@@ -26,8 +26,7 @@ import time
import
traceback
from
gevent.core
import
active_event
from
gevent.hub
import
get_hub
,
getcurrent
,
sleep
from
gevent.rawgreenlet
import
spawn
from
gevent.hub
import
get_hub
,
getcurrent
,
sleep
,
spawn_raw
class
Cancelled
(
RuntimeError
):
...
...
@@ -54,7 +53,7 @@ class event(object):
>>> def baz(b):
... evt.send(b + 1)
...
>>> _ = spawn(baz, 3)
>>> _ = spawn
_raw
(baz, 3)
>>> evt.wait()
4
"""
...
...
@@ -138,7 +137,7 @@ class event(object):
>>> def wait_on():
... retval = evt.wait()
... print "waited for", retval
>>> _ = spawn(wait_on)
>>> _ = spawn
_raw
(wait_on)
>>> evt.send('result')
>>> sleep(0)
waited for result
...
...
@@ -168,7 +167,7 @@ class event(object):
... print 'about to wait'
... result = evt.wait()
... print 'waited for', result
>>> _ = spawn(waiter)
>>> _ = spawn
_raw
(waiter)
>>> sleep(0)
about to wait
>>> evt.send('a')
...
...
@@ -350,7 +349,7 @@ def execute(func, *args, **kw):
evt
=
event
()
def
_really_execute
():
evt
.
send
(
func
(
*
args
,
**
kw
))
spawn
(
_really_execute
)
spawn
_raw
(
_really_execute
)
return
evt
...
...
gevent/hub.py
View file @
cb9e7f63
...
...
@@ -6,6 +6,7 @@ from gevent import core
__all__
=
[
'getcurrent'
,
'GreenletExit'
,
'spawn_raw'
,
'sleep'
,
'kill'
,
'signal'
,
...
...
@@ -33,6 +34,22 @@ except AttributeError:
__all__
.
remove
(
'fork'
)
def
_switch_helper
(
function
,
args
,
kwargs
):
# work around the fact that greenlet.switch does not support keyword args
return
function
(
*
args
,
**
kwargs
)
def
spawn_raw
(
function
,
*
args
,
**
kwargs
):
if
kwargs
:
g
=
greenlet
(
_switch_helper
,
get_hub
())
core
.
active_event
(
g
.
switch
,
function
,
args
,
kwargs
)
return
g
else
:
g
=
greenlet
(
function
,
get_hub
())
core
.
active_event
(
g
.
switch
,
*
args
)
return
g
def
sleep
(
seconds
=
0
):
"""Yield control to another eligible coroutine until at least *seconds* have
elapsed.
...
...
gevent/proc.py
View file @
cb9e7f63
...
...
@@ -575,7 +575,7 @@ class Proc(Source):
assert
self
.
greenlet
is
None
,
"'run' can only be called once per instance"
if
self
.
name
is
None
:
self
.
name
=
str
(
function
)
self
.
greenlet
=
rawgreenlet
.
spawn
(
self
.
_run
,
function
,
args
,
kwargs
)
self
.
greenlet
=
hub
.
spawn_raw
(
self
.
_run
,
function
,
args
,
kwargs
)
def
_run
(
self
,
function
,
args
,
kwargs
):
"""Internal top level function.
...
...
@@ -818,7 +818,7 @@ class Pool(object):
def
execute_async
(
self
,
func
,
*
args
,
**
kwargs
):
if
self
.
sem
.
locked
():
return
rawgreenlet
.
spawn
(
self
.
execute
,
func
,
*
args
,
**
kwargs
)
return
hub
.
spawn_raw
(
self
.
execute
,
func
,
*
args
,
**
kwargs
)
else
:
return
self
.
execute
(
func
,
*
args
,
**
kwargs
)
...
...
gevent/rawgreenlet.py
View file @
cb9e7f63
"""A few utilities for raw greenlets"""
"""A few utilities for raw greenlets.
# XXX these functions do not support 'timeout' parameter as gevent.greenlet API
# XXX this module does seem to be useful and may be removed in the future
"""
import
traceback
from
gevent
import
core
from
gevent.hub
import
greenlet
,
get_hub
,
GreenletExit
,
Waiter
,
sleep
from
gevent.hub
import
GreenletExit
,
Waiter
,
sleep
__all__
=
[
'spawn'
,
'spawn_later'
,
'kill'
,
__all__
=
[
'kill'
,
'killall'
,
'join'
,
'joinall'
]
def
_switch_helper
(
function
,
args
,
kwargs
):
# work around the fact that greenlet.switch does not support keyword args
return
function
(
*
args
,
**
kwargs
)
def
spawn
(
function
,
*
args
,
**
kwargs
):
if
kwargs
:
g
=
greenlet
(
_switch_helper
,
get_hub
())
core
.
active_event
(
g
.
switch
,
function
,
args
,
kwargs
)
return
g
else
:
g
=
greenlet
(
function
,
get_hub
())
core
.
active_event
(
g
.
switch
,
*
args
)
return
g
def
spawn_later
(
seconds
,
function
,
*
args
,
**
kwargs
):
if
kwargs
:
g
=
greenlet
(
_switch_helper
,
get_hub
())
core
.
timer
(
seconds
,
g
.
switch
,
function
,
args
,
kwargs
)
return
g
else
:
g
=
greenlet
(
function
,
get_hub
())
core
.
timer
(
seconds
,
g
.
switch
,
*
args
)
return
g
def
_kill
(
greenlet
,
exception
,
waiter
):
try
:
greenlet
.
throw
(
exception
)
...
...
gevent/socket.py
View file @
cb9e7f63
...
...
@@ -35,8 +35,7 @@ import sys
import
errno
import
time
from
gevent.hub
import
getcurrent
,
get_hub
from
gevent.rawgreenlet
import
spawn
from
gevent.hub
import
getcurrent
,
get_hub
,
spawn_raw
from
gevent
import
core
BUFFER_SIZE
=
4096
...
...
@@ -520,7 +519,7 @@ def tcp_server(listensocket, server, *args, **kw):
try
:
while
True
:
client_socket
=
listensocket
.
accept
()
spawn
(
server
,
client_socket
,
*
args
,
**
kw
)
spawn
_raw
(
server
,
client_socket
,
*
args
,
**
kw
)
except
error
,
e
:
# Broken pipe means it was shutdown
if
e
[
0
]
!=
32
:
...
...
gevent/thread.py
View file @
cb9e7f63
"""implements standard module 'thread' with greenlets"""
__thread
=
__import__
(
'thread'
)
from
gevent.hub
import
getcurrent
,
GreenletExit
from
gevent.rawgreenlet
import
spawn
from
gevent.hub
import
getcurrent
,
GreenletExit
,
spawn_raw
from
gevent.coros
import
Semaphore
as
LockType
def
get_ident
(
gr
=
None
):
...
...
@@ -11,7 +10,7 @@ def get_ident(gr=None):
return
id
(
gr
)
def
start_new_thread
(
function
,
args
=
(),
kwargs
=
{}):
g
=
spawn
(
function
,
*
args
,
**
kwargs
)
g
=
spawn
_raw
(
function
,
*
args
,
**
kwargs
)
return
get_ident
(
g
)
def
allocate_lock
():
...
...
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