Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pyfs
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
pyfs
Commits
358d7f1d
Commit
358d7f1d
authored
Sep 13, 2010
by
rfkelly0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make WatchableFSMixin instances picklable, by discarding watchers
parent
d9372743
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
2 deletions
+22
-2
fs/watch.py
+22
-2
No files found.
fs/watch.py
View file @
358d7f1d
...
...
@@ -141,6 +141,15 @@ class WatchableFSMixin(FS):
self
.
_watchers
=
PathMap
()
super
(
WatchableFSMixin
,
self
)
.
__init__
(
*
args
,
**
kwds
)
def
__getstate__
(
self
):
state
=
super
(
WatchableFSMixin
,
self
)
.
__getstate__
()
state
.
pop
(
"_watchers"
,
None
)
return
state
def
__setstate__
(
self
,
state
):
super
(
WatchableFSMixin
,
self
)
.
__setstate__
(
state
)
self
.
_watchers
=
PathMap
()
def
add_watcher
(
self
,
callback
,
path
=
"/"
,
events
=
None
,
recursive
=
True
):
"""Add a watcher callback to the FS."""
w
=
Watcher
(
self
,
callback
,
path
,
events
,
recursive
=
recursive
)
...
...
@@ -165,9 +174,14 @@ class WatchableFSMixin(FS):
if
watcher
.
callback
is
callback
:
yield
watcher
def
notify_watchers
(
self
,
event_class
,
path
=
None
,
*
args
,
**
kwds
):
def
notify_watchers
(
self
,
event_
or_
class
,
path
=
None
,
*
args
,
**
kwds
):
"""Notify watchers of the given event data."""
event
=
event_class
(
self
,
path
,
*
args
,
**
kwds
)
if
isinstance
(
event_or_class
,
EVENT
):
event
=
event_or_class
else
:
event
=
event_or_class
(
self
,
path
,
*
args
,
**
kwds
)
if
path
is
None
:
path
=
event
.
path
if
path
is
None
:
for
watchers
in
self
.
_watchers
.
itervalues
():
for
watcher
in
watchers
:
...
...
@@ -472,7 +486,13 @@ def ensure_watchable(fs,wrapper_class=PollingWatchableFS,*args,**kwds):
for watcher callbacks. This may be the original object if it supports them
natively, or a wrapper class if they must be simulated.
"""
if
isinstance
(
fs
,
wrapper_class
):
return
fs
try
:
# Try to add a watcher to a path that's unlikely to exist.
# It's OK if the path does exist, since we remove the watcher.
# It just might be slightly slower as the fs will actually have
# to establish the watcher.
w
=
fs
.
add_watcher
(
lambda
e
:
None
,
"/somepaththatsnotlikelytoexist"
)
except
(
AttributeError
,
UnsupportedError
):
return
wrapper_class
(
fs
,
*
args
,
**
kwds
)
...
...
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