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
debd626e
Commit
debd626e
authored
Oct 29, 2015
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
corecffi: move some runtime lookups of cffi types and callbacks to import time.
parent
f466ec51
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
3 deletions
+21
-3
gevent/corecffi.py
gevent/corecffi.py
+21
-3
No files found.
gevent/corecffi.py
View file @
debd626e
...
...
@@ -964,19 +964,25 @@ class watcher(object):
self
.
args
=
None
self
.
_callback
=
None
self
.
_handle
=
ffi
.
new_handle
(
self
)
# XXX This parses the C every time. Is that expensive? Can we do better?
self
.
_gwatcher
=
ffi
.
new
(
'struct gevent_'
+
self
.
_watcher_type
+
'*'
)
self
.
_gwatcher
=
ffi
.
new
(
self
.
_watcher_struct_pointer_type
)
self
.
_watcher
=
ffi
.
addressof
(
self
.
_gwatcher
.
watcher
)
self
.
_gwatcher
.
handle
=
self
.
_handle
if
priority
is
not
None
:
libev
.
ev_set_priority
(
self
.
_watcher
,
priority
)
self
.
_watcher_init
(
self
.
_watcher
,
getattr
(
libev
,
'_gevent_'
+
self
.
_watcher_type
+
'_callback'
)
,
self
.
_watcher_callback
,
*
args
)
# A string identifying the type of libev object we watch, e.g., 'ev_io'
# This should be a class attribute.
_watcher_type
=
None
# A cffi ctype object identifying the struct pointer we create.
# This is a class attribute set based on the _watcher_type
_watcher_struct_pointer_type
=
None
# The attribute of the libev object identifying the custom
# callback function for this type of watcher. This is a class
# attribute set based on the _watcher_type
_watcher_callback
=
None
def
_watcher_init
(
self
,
watcher_ptr
,
cb
,
*
args
):
"Init the watcher. Subclasses must define."
...
...
@@ -990,6 +996,13 @@ class watcher(object):
"Stop the watcher. Subclasses must define."
raise
NotImplementedError
()
@
classmethod
def
_init_subclasses
(
cls
):
for
subclass
in
cls
.
__subclasses__
():
watcher_type
=
subclass
.
_watcher_type
subclass
.
_watcher_struct_pointer_type
=
ffi
.
typeof
(
'struct gevent_'
+
watcher_type
+
'*'
)
subclass
.
_watcher_callback
=
getattr
(
libev
,
'_gevent_'
+
watcher_type
+
'_callback'
)
# this is not needed, since we keep alive the watcher while it's started
#def __del__(self):
# self._watcher_stop(self.loop._ptr, self._watcher)
...
...
@@ -1316,6 +1329,11 @@ class stat(watcher):
def
interval
(
self
):
return
self
.
_watcher
.
interval
# All watcher subclasses must be declared above. Now we do some
# initialization; this is not only a minor optimization, it protects
# against later runtime typos and attribute errors
watcher
.
_init_subclasses
()
def
_syserr_cb
(
msg
):
try
:
...
...
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