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
98ef59ed
Commit
98ef59ed
authored
Sep 15, 2010
by
Denis Bilenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify code in core.pyx
parent
324e0a12
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
36 deletions
+16
-36
gevent/core.pyx
gevent/core.pyx
+16
-36
No files found.
gevent/core.pyx
View file @
98ef59ed
...
...
@@ -149,7 +149,7 @@ cdef extern from "libevent.h":
cdef
void
__event_handler
(
int
fd
,
short
evtype
,
void
*
arg
)
with
gil
:
cdef
event
self
=
<
event
>
arg
try
:
self
.
_
callback
(
self
,
evtype
)
self
.
callback
(
self
,
evtype
)
except
:
traceback
.
print_exc
()
try
:
...
...
@@ -171,12 +171,13 @@ cdef class event:
- *arg* -- optional object, which will be made available as :attr:`arg` property.
"""
cdef
event_t
ev
cdef
object
_callback
,
_arg
cdef
public
object
callback
cdef
public
object
arg
cdef
int
_incref
# 1 if we already INCREFed this object once (because libevent references it)
def
__init__
(
self
,
short
evtype
,
int
handle
,
callback
,
arg
=
None
):
self
.
_
callback
=
callback
self
.
_
arg
=
arg
self
.
callback
=
callback
self
.
arg
=
arg
self
.
_incref
=
0
cdef
void
*
c_self
=
<
void
*>
self
if
evtype
==
0
and
not
handle
:
...
...
@@ -194,27 +195,6 @@ cdef class event:
Py_DECREF
(
self
)
self
.
_incref
-=
1
property
callback
:
"""User callback that will be called once the event is signalled.
The prototype: ``callback(event instance, evtype)``.
"""
def
__get__
(
self
):
return
self
.
_callback
def
__set__
(
self
,
new
):
self
.
_callback
=
new
property
arg
:
"""Optional object set and read only by the user."""
def
__get__
(
self
):
return
self
.
_arg
def
__set__
(
self
,
new
):
self
.
_arg
=
new
property
pending
:
"""Return True if the event is still scheduled to run."""
...
...
@@ -317,7 +297,7 @@ cdef class event:
else
:
events_str
=
''
return
'<%s at %s%s fd=%s%s flags=%s cb=%s arg=%s>'
%
\
(
type
(
self
).
__name__
,
hex
(
id
(
self
)),
pending
,
self
.
fd
,
events_str
,
self
.
flags_str
,
self
.
_callback
,
self
.
_
arg
)
(
type
(
self
).
__name__
,
hex
(
id
(
self
)),
pending
,
self
.
fd
,
events_str
,
self
.
flags_str
,
self
.
callback
,
self
.
arg
)
def
__str__
(
self
):
if
self
.
pending
:
...
...
@@ -328,8 +308,8 @@ cdef class event:
events_str
=
' %s'
%
self
.
events_str
else
:
events_str
=
''
cb
=
str
(
self
.
_
callback
).
replace
(
'
\
n
'
,
'
\
n
'
+
' '
*
8
)
arg
=
pformat
(
self
.
_
arg
,
indent
=
2
).
replace
(
'
\
n
'
,
'
\
n
'
+
' '
*
8
)
cb
=
str
(
self
.
callback
).
replace
(
'
\
n
'
,
'
\
n
'
+
' '
*
8
)
arg
=
pformat
(
self
.
arg
,
indent
=
2
).
replace
(
'
\
n
'
,
'
\
n
'
+
' '
*
8
)
return
'%s%s fd=%s%s flags=%s
\
n
cb = %s
\
n
arg = %s'
%
\
(
type
(
self
).
__name__
,
pending
,
self
.
fd
,
events_str
,
self
.
flags_str
,
cb
,
arg
)
...
...
@@ -376,8 +356,8 @@ class readwrite_event(event):
cdef
void
__simple_handler
(
int
fd
,
short
evtype
,
void
*
arg
)
with
gil
:
cdef
event
self
=
<
event
>
arg
try
:
args
,
kwargs
=
self
.
_
arg
self
.
_
callback
(
*
args
,
**
kwargs
)
args
,
kwargs
=
self
.
arg
self
.
callback
(
*
args
,
**
kwargs
)
except
:
traceback
.
print_exc
()
try
:
...
...
@@ -394,8 +374,8 @@ cdef class timer(event):
"""Create a new scheduled timer"""
def
__init__
(
self
,
float
seconds
,
callback
,
*
args
,
**
kwargs
):
self
.
_
callback
=
callback
self
.
_
arg
=
(
args
,
kwargs
)
self
.
callback
=
callback
self
.
arg
=
(
args
,
kwargs
)
evtimer_set
(
&
self
.
ev
,
__simple_handler
,
<
void
*>
self
)
self
.
add
(
seconds
)
...
...
@@ -404,8 +384,8 @@ cdef class signal(event):
"""Create a new persistent signal event"""
def
__init__
(
self
,
int
signalnum
,
callback
,
*
args
,
**
kwargs
):
self
.
_
callback
=
callback
self
.
_
arg
=
(
args
,
kwargs
)
self
.
callback
=
callback
self
.
arg
=
(
args
,
kwargs
)
event_set
(
&
self
.
ev
,
signalnum
,
EV_SIGNAL
|
EV_PERSIST
,
__simple_handler
,
<
void
*>
self
)
self
.
add
()
...
...
@@ -414,8 +394,8 @@ cdef class active_event(event):
"""An event that is scheduled to run in the current loop iteration"""
def
__init__
(
self
,
callback
,
*
args
,
**
kwargs
):
self
.
_
callback
=
callback
self
.
_
arg
=
(
args
,
kwargs
)
self
.
callback
=
callback
self
.
arg
=
(
args
,
kwargs
)
evtimer_set
(
&
self
.
ev
,
__simple_handler
,
<
void
*>
self
)
self
.
_addref
()
event_active
(
&
self
.
ev
,
EV_TIMEOUT
,
1
)
...
...
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