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
41459867
Commit
41459867
authored
Apr 14, 2010
by
rfkelly0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
osfs/watch_win32: enqueue all IO operations from the same thread
parent
c2c878d8
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
3 deletions
+30
-3
fs/osfs/watch_win32.py
+30
-3
No files found.
fs/osfs/watch_win32.py
View file @
41459867
...
@@ -15,6 +15,7 @@ import stat
...
@@ -15,6 +15,7 @@ import stat
import
struct
import
struct
import
ctypes
import
ctypes
import
ctypes.wintypes
import
ctypes.wintypes
import
traceback
from
fs.errors
import
*
from
fs.errors
import
*
from
fs.path
import
*
from
fs.path
import
*
...
@@ -194,6 +195,7 @@ class WatchedDirectory(object):
...
@@ -194,6 +195,7 @@ class WatchedDirectory(object):
None
)
None
)
self
.
result
=
ctypes
.
create_string_buffer
(
1024
)
self
.
result
=
ctypes
.
create_string_buffer
(
1024
)
self
.
overlapped
=
overlapped
=
OVERLAPPED
()
self
.
overlapped
=
overlapped
=
OVERLAPPED
()
self
.
ready
=
threading
.
Event
()
def
__del__
(
self
):
def
__del__
(
self
):
self
.
close
()
self
.
close
()
...
@@ -243,11 +245,14 @@ class WatchThread(threading.Thread):
...
@@ -243,11 +245,14 @@ class WatchThread(threading.Thread):
super
(
WatchThread
,
self
)
.
__init__
()
super
(
WatchThread
,
self
)
.
__init__
()
self
.
closed
=
False
self
.
closed
=
False
self
.
watched_directories
=
{}
self
.
watched_directories
=
{}
self
.
_iocp
=
CreateIoCompletionPort
(
INVALID_HANDLE_VALUE
,
None
,
0
,
1
)
self
.
ready
=
threading
.
Event
()
self
.
_iocp
=
None
self
.
_new_watches
=
Queue
.
Queue
()
def
close
(
self
):
def
close
(
self
):
if
not
self
.
closed
:
if
not
self
.
closed
:
self
.
closed
=
True
self
.
closed
=
True
if
self
.
_iocp
:
PostQueuedCompletionStatus
(
self
.
_iocp
,
0
,
1
,
None
)
PostQueuedCompletionStatus
(
self
.
_iocp
,
0
,
1
,
None
)
def
add_watcher
(
self
,
callback
,
path
,
events
,
recursive
):
def
add_watcher
(
self
,
callback
,
path
,
events
,
recursive
):
...
@@ -330,28 +335,46 @@ class WatchThread(threading.Thread):
...
@@ -330,28 +335,46 @@ class WatchThread(threading.Thread):
def
run
(
self
):
def
run
(
self
):
try
:
try
:
self
.
_iocp
=
CreateIoCompletionPort
(
INVALID_HANDLE_VALUE
,
None
,
0
,
1
)
self
.
ready
.
set
()
nbytes
=
ctypes
.
wintypes
.
DWORD
()
nbytes
=
ctypes
.
wintypes
.
DWORD
()
iocpkey
=
ctypes
.
wintypes
.
DWORD
()
iocpkey
=
ctypes
.
wintypes
.
DWORD
()
overlapped
=
OVERLAPPED
()
overlapped
=
OVERLAPPED
()
while
not
self
.
closed
:
while
not
self
.
closed
:
try
:
GetQueuedCompletionStatus
(
self
.
_iocp
,
GetQueuedCompletionStatus
(
self
.
_iocp
,
ctypes
.
byref
(
nbytes
),
ctypes
.
byref
(
nbytes
),
ctypes
.
byref
(
iocpkey
),
ctypes
.
byref
(
iocpkey
),
ctypes
.
byref
(
overlapped
),
ctypes
.
byref
(
overlapped
),
-
1
)
-
1
)
except
WindowsError
:
traceback
.
print_exc
()
else
:
if
iocpkey
.
value
>
1
:
if
iocpkey
.
value
>
1
:
w
=
self
.
watched_directories
[
iocpkey
.
value
]
w
=
self
.
watched_directories
[
iocpkey
.
value
]
w
.
complete
(
nbytes
.
value
)
w
.
complete
(
nbytes
.
value
)
w
.
post
()
w
.
post
()
elif
not
self
.
closed
:
try
:
while
True
:
w
=
self
.
_new_watches
.
get_nowait
()
CreateIoCompletionPort
(
w
.
handle
,
self
.
_iocp
,
hash
(
w
),
0
)
w
.
post
()
w
.
ready
.
set
()
except
Queue
.
Empty
:
pass
finally
:
finally
:
self
.
ready
.
set
()
for
w
in
self
.
watched_directories
.
itervalues
():
for
w
in
self
.
watched_directories
.
itervalues
():
w
.
close
()
w
.
close
()
if
self
.
_iocp
:
CloseHandle
(
self
.
_iocp
)
CloseHandle
(
self
.
_iocp
)
def
attach_watched_directory
(
self
,
w
):
def
attach_watched_directory
(
self
,
w
):
self
.
watched_directories
[
hash
(
w
)]
=
w
self
.
watched_directories
[
hash
(
w
)]
=
w
CreateIoCompletionPort
(
w
.
handle
,
self
.
_iocp
,
hash
(
w
),
0
)
self
.
_new_watches
.
put
(
w
)
w
.
post
()
PostQueuedCompletionStatus
(
self
.
_iocp
,
0
,
1
,
None
)
w
.
ready
.
wait
()
class
OSFSWatchMixin
(
WatchableFSMixin
):
class
OSFSWatchMixin
(
WatchableFSMixin
):
...
@@ -402,6 +425,7 @@ class OSFSWatchMixin(WatchableFSMixin):
...
@@ -402,6 +425,7 @@ class OSFSWatchMixin(WatchableFSMixin):
if
self
.
__watch_thread
is
None
:
if
self
.
__watch_thread
is
None
:
wt
=
WatchThread
()
wt
=
WatchThread
()
wt
.
start
()
wt
.
start
()
wt
.
ready
.
wait
()
OSFSWatchMixin
.
__watch_thread
=
wt
OSFSWatchMixin
.
__watch_thread
=
wt
finally
:
finally
:
self
.
__watch_lock
.
release
()
self
.
__watch_lock
.
release
()
...
@@ -415,7 +439,10 @@ class OSFSWatchMixin(WatchableFSMixin):
...
@@ -415,7 +439,10 @@ class OSFSWatchMixin(WatchableFSMixin):
return
return
if
not
force
and
OSFSWatchMixin
.
__watch_thread
.
watched_directories
:
if
not
force
and
OSFSWatchMixin
.
__watch_thread
.
watched_directories
:
return
return
try
:
OSFSWatchMixin
.
__watch_thread
.
close
()
OSFSWatchMixin
.
__watch_thread
.
close
()
except
EnvironmentError
:
pass
OSFSWatchMixin
.
__watch_thread
=
None
OSFSWatchMixin
.
__watch_thread
=
None
finally
:
finally
:
self
.
__watch_lock
.
release
()
self
.
__watch_lock
.
release
()
...
...
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