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
c8e473aa
Commit
c8e473aa
authored
Apr 17, 2015
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improvements to path watching: set the path earlier, make the test more comprehensive.
parent
546c5218
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
7 deletions
+26
-7
gevent/corecffi.py
gevent/corecffi.py
+16
-6
greentest/test__core_stat.py
greentest/test__core_stat.py
+10
-1
No files found.
gevent/corecffi.py
View file @
c8e473aa
...
...
@@ -1067,19 +1067,29 @@ class stat(watcher):
_watcher_ffi_cb
=
"void(*)(struct ev_loop *, struct %s *, int)"
%
_watcher_type
def
__init__
(
self
,
_loop
,
path
,
interval
=
0.0
,
ref
=
True
,
priority
=
None
):
self
.
path
=
path
watcher
.
__init__
(
self
,
_loop
,
ref
=
ref
,
priority
=
priority
,
args
=
(
path
,
interval
))
# XXX: self._watcher.path is not getting properly set at the C level
# (Possibly because ev_stat_init is actually a macro? I don't know)
# Something overwrites it or fails to set it. We reset it in start() method
if
not
isinstance
(
path
,
bytes
):
# XXX: Filesystem encoding? Python itself has issues here, were they fixed?
path
=
path
.
encode
(
'utf-8'
)
watcher
.
__init__
(
self
,
_loop
,
ref
=
ref
,
priority
=
priority
,
# cffi doesn't automatically marshal byte strings to
# char* in the function call; instead it passes an
# empty string or garbage pointer. If the watcher's
# path is incorrect, watching silently fails
# (the underlying call to lstat() keeps erroring out)
args
=
(
ffi
.
new
(
'char[]'
,
path
),
interval
))
def
start
(
self
,
callback
,
*
args
):
self
.
_watcher
.
path
=
ffi
.
new
(
"char[]"
,
self
.
path
)
watcher
.
start
(
self
,
callback
,
*
args
)
def
stop
(
self
):
watcher
.
stop
(
self
)
@
property
def
path
(
self
):
return
ffi
.
string
(
self
.
_watcher
.
path
)
@
property
def
attr
(
self
):
if
not
self
.
_watcher
.
attr
.
st_nlink
:
...
...
greentest/test__core_stat.py
View file @
c8e473aa
...
...
@@ -23,7 +23,14 @@ try:
f
.
close
()
greenlet
=
gevent
.
spawn_later
(
DELAY
,
write
)
watcher
=
hub
.
loop
.
stat
(
filename
)
# If we don't specify an interval, we default to zero.
# libev interprets that as meaning to use its default interval,
# which is about 5 seconds. If we go below it's minimum check
# threshold, it bumps it up to the minimum.
watcher
=
hub
.
loop
.
stat
(
filename
,
interval
=-
1
)
if
hasattr
(
watcher
,
'path'
):
assert
watcher
.
path
==
filename
assert
watcher
.
interval
==
-
1
start
=
time
.
time
()
...
...
@@ -37,6 +44,8 @@ try:
assert
reaction
>=
0.0
,
'Watcher %s reacted too early (write): %.3fs'
%
(
watcher
,
reaction
)
assert
watcher
.
attr
is
not
None
,
watcher
.
attr
assert
watcher
.
prev
is
not
None
,
watcher
.
prev
# The watcher interval changed after it started; -1 is illegal
assert
watcher
.
interval
!=
-
1
greenlet
.
join
()
gevent
.
spawn_later
(
DELAY
,
os
.
unlink
,
filename
)
...
...
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