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
d83df914
Commit
d83df914
authored
Apr 08, 2016
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test__core_timer libuv.
parent
98965e0b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
23 deletions
+41
-23
src/gevent/_ffi/watcher.py
src/gevent/_ffi/watcher.py
+19
-13
src/gevent/libev/watcher.py
src/gevent/libev/watcher.py
+3
-6
src/gevent/libuv/watcher.py
src/gevent/libuv/watcher.py
+14
-0
src/greentest/test__core_timer.py
src/greentest/test__core_timer.py
+5
-4
No files found.
src/gevent/_ffi/watcher.py
View file @
d83df914
...
...
@@ -7,7 +7,7 @@ from __future__ import absolute_import, print_function
import
sys
import
os
import
signal
as
signalmodule
import
functools
from
gevent._ffi.loop
import
GEVENT_CORE_EVENTS
from
gevent._ffi.loop
import
_NOARGS
...
...
@@ -17,6 +17,15 @@ __all__ = [
]
def
not_while_active
(
func
):
@
functools
.
wraps
(
func
)
def
nw
(
self
,
*
args
,
**
kwargs
):
if
self
.
active
:
raise
AttributeError
(
"not while active"
)
func
(
self
,
*
args
,
**
kwargs
)
return
nw
class
LazyOnClass
(
object
):
@
classmethod
...
...
@@ -164,6 +173,12 @@ class watcher(object):
def
_watcher_ffi_unref
(
self
):
raise
NotImplementedError
()
def
_watcher_ffi_start_unref
(
self
):
self
.
_watcher_ffi_unref
()
def
_watcher_ffi_stop_ref
(
self
):
self
.
_watcher_ffi_ref
()
# A string identifying the type of libev object we watch, e.g., 'ev_io'
# This should be a class attribute.
_watcher_type
=
None
...
...
@@ -243,12 +258,12 @@ class watcher(object):
raise
TypeError
(
'callback must be callable, not None'
)
self
.
callback
=
callback
self
.
args
=
args
or
_NOARGS
self
.
_watcher_ffi_unref
()
self
.
_watcher_ffi_
start_
unref
()
self
.
loop
.
_keepaliveset
.
add
(
self
)
self
.
_watcher_ffi_start
()
def
stop
(
self
):
self
.
_watcher_ffi_ref
()
self
.
_watcher_ffi_
stop_
ref
()
self
.
_watcher_ffi_stop
()
self
.
loop
.
_keepaliveset
.
discard
(
self
)
...
...
@@ -258,6 +273,7 @@ class watcher(object):
def
_get_priority
(
self
):
return
None
@
not_while_active
def
_set_priority
(
self
,
priority
):
pass
...
...
@@ -274,16 +290,6 @@ class watcher(object):
watcher
=
AbstractWatcherType
(
'watcher'
,
(
object
,),
dict
(
watcher
.
__dict__
))
import
functools
def
not_while_active
(
func
):
@
functools
.
wraps
(
func
)
def
nw
(
self
,
*
args
,
**
kwargs
):
if
self
.
active
:
raise
AttributeError
(
"not while active"
)
func
(
self
,
*
args
,
**
kwargs
)
return
nw
class
IoMixin
(
object
):
EVENT_MASK
=
0
...
...
src/gevent/libev/watcher.py
View file @
d83df914
...
...
@@ -121,9 +121,8 @@ class watcher(_base.watcher):
def
_get_priority
(
self
):
return
libev
.
ev_priority
(
self
.
_watcher
)
@
_base
.
not_while_active
def
_set_priority
(
self
,
priority
):
if
libev
.
ev_is_active
(
self
.
_watcher
):
raise
AttributeError
(
"Cannot set priority of an active watcher"
)
libev
.
ev_set_priority
(
self
.
_watcher
,
priority
)
priority
=
property
(
_get_priority
,
_set_priority
)
...
...
@@ -151,9 +150,8 @@ class io(_base.IoMixin, watcher):
def
_get_fd
(
self
):
return
vfd_get
(
self
.
_watcher
.
fd
)
@
_base
.
not_while_active
def
_set_fd
(
self
,
fd
):
if
libev
.
ev_is_active
(
self
.
_watcher
):
raise
AttributeError
(
"'io' watcher attribute 'fd' is read-only while watcher is active"
)
vfd
=
vfd_open
(
fd
)
vfd_free
(
self
.
_watcher
.
fd
)
self
.
_watcher_init
(
self
.
_watcher
,
self
.
_watcher_callback
,
vfd
,
self
.
_watcher
.
events
)
...
...
@@ -163,9 +161,8 @@ class io(_base.IoMixin, watcher):
def
_get_events
(
self
):
return
self
.
_watcher
.
events
@
_base
.
not_while_active
def
_set_events
(
self
,
events
):
if
libev
.
ev_is_active
(
self
.
_watcher
):
raise
AttributeError
(
"'io' watcher attribute 'events' is read-only while watcher is active"
)
self
.
_watcher_init
(
self
.
_watcher
,
self
.
_watcher_callback
,
self
.
_watcher
.
fd
,
events
)
events
=
property
(
_get_events
,
_set_events
)
...
...
src/gevent/libuv/watcher.py
View file @
d83df914
...
...
@@ -41,6 +41,14 @@ class watcher(_base.watcher):
def
_watcher_ffi_unref
(
self
):
libuv
.
uv_unref
(
self
.
_watcher
)
def
_watcher_ffi_start_unref
(
self
):
# libev manipulates these refs at start and stop for
# some reason; we don't
pass
def
_watcher_ffi_stop_ref
(
self
):
pass
def
_get_ref
(
self
):
return
libuv
.
uv_has_ref
(
self
.
_watcher
)
...
...
@@ -134,6 +142,12 @@ class timer(_base.TimerMixin, watcher):
int
(
self
.
_repeat
*
1000
))
def
again
(
self
,
callback
,
*
args
,
**
kw
):
if
not
self
.
active
:
# If we've never been started, this is the same as starting us.
# libuv makes the distinction, libev doesn't.
self
.
start
(
callback
,
*
args
,
**
kw
)
return
self
.
_again
=
True
try
:
self
.
start
(
callback
,
*
args
,
**
kw
)
...
...
src/greentest/test__core_timer.py
View file @
d83df914
...
...
@@ -16,7 +16,7 @@ def main():
x
.
start
(
f
)
if
hasattr
(
loop
,
'_keepaliveset'
):
assert
x
in
loop
.
_keepaliveset
assert
x
.
active
,
x
.
pending
assert
x
.
active
,
(
"active"
,
x
.
active
,
"pending"
,
x
.
pending
)
try
:
x
.
priority
=
1
raise
AssertionError
(
'must not be able to change priority of active watcher'
)
...
...
@@ -27,9 +27,10 @@ def main():
assert
called
==
[
1
],
called
assert
x
.
callback
is
None
,
x
.
callback
assert
x
.
args
is
None
,
x
.
args
assert
x
.
priority
==
0
,
x
x
.
priority
=
1
assert
x
.
priority
==
1
,
x
if
x
.
priority
is
not
None
:
assert
x
.
priority
==
0
,
(
x
,
x
.
priority
)
x
.
priority
=
1
assert
x
.
priority
==
1
,
x
x
.
stop
()
if
hasattr
(
loop
,
'_keepaliveset'
):
assert
x
not
in
loop
.
_keepaliveset
...
...
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