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
95cc2ab6
Commit
95cc2ab6
authored
Apr 19, 2011
by
rfkelly0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dokan: improve thread-safety of timeout-protection mechanism
parent
37f7c843
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
14 deletions
+28
-14
fs/expose/dokan/__init__.py
+28
-14
No files found.
fs/expose/dokan/__init__.py
View file @
95cc2ab6
...
@@ -67,7 +67,7 @@ import subprocess
...
@@ -67,7 +67,7 @@ import subprocess
import
cPickle
import
cPickle
import
datetime
import
datetime
import
ctypes
import
ctypes
import
Que
ue
from
collections
import
deq
ue
from
fs.base
import
threading
from
fs.base
import
threading
from
fs.errors
import
*
from
fs.errors
import
*
...
@@ -197,7 +197,8 @@ def handle_fs_errors(func):
...
@@ -197,7 +197,8 @@ def handle_fs_errors(func):
_TIMEOUT_PROTECT_THREAD
=
None
_TIMEOUT_PROTECT_THREAD
=
None
_TIMEOUT_PROTECT_LOCK
=
threading
.
Lock
()
_TIMEOUT_PROTECT_LOCK
=
threading
.
Lock
()
_TIMEOUT_PROTECT_QUEUE
=
Queue
.
Queue
()
_TIMEOUT_PROTECT_COND
=
threading
.
Condition
(
_TIMEOUT_PROTECT_LOCK
)
_TIMEOUT_PROTECT_QUEUE
=
deque
()
_TIMEOUT_PROTECT_WAIT_TIME
=
4
*
60
_TIMEOUT_PROTECT_WAIT_TIME
=
4
*
60
_TIMEOUT_PROTECT_RESET_TIME
=
5
*
60
*
1000
_TIMEOUT_PROTECT_RESET_TIME
=
5
*
60
*
1000
...
@@ -211,20 +212,30 @@ def _start_timeout_protect_thread():
...
@@ -211,20 +212,30 @@ def _start_timeout_protect_thread():
global
_TIMEOUT_PROTECT_THREAD
global
_TIMEOUT_PROTECT_THREAD
with
_TIMEOUT_PROTECT_LOCK
:
with
_TIMEOUT_PROTECT_LOCK
:
if
_TIMEOUT_PROTECT_THREAD
is
None
:
if
_TIMEOUT_PROTECT_THREAD
is
None
:
def
target
():
target
=
_run_timeout_protect_thread
while
True
:
(
when
,
info
,
finished
)
=
_TIMEOUT_PROTECT_QUEUE
.
get
()
if
finished
:
continue
now
=
time
.
time
()
wait_time
=
max
(
0
,
_TIMEOUT_PROTECT_WAIT_TIME
-
now
+
when
)
time
.
sleep
(
wait_time
)
libdokan
.
DokanResetTimeout
(
_TIMEOUT_PROTECT_RESET_TIME
,
info
)
_TIMEOUT_PROTECT_QUEUE
.
put
((
now
+
wait_time
,
info
,
finished
))
_TIMEOUT_PROTECT_THREAD
=
threading
.
Thread
(
target
=
target
)
_TIMEOUT_PROTECT_THREAD
=
threading
.
Thread
(
target
=
target
)
_TIMEOUT_PROTECT_THREAD
.
daemon
=
True
_TIMEOUT_PROTECT_THREAD
.
daemon
=
True
_TIMEOUT_PROTECT_THREAD
.
start
()
_TIMEOUT_PROTECT_THREAD
.
start
()
def
_run_timeout_protect_thread
():
while
True
:
with
_TIMEOUT_PROTECT_COND
:
try
:
(
when
,
info
,
finished
)
=
_TIMEOUT_PROTECT_QUEUE
.
popleft
()
except
IndexError
:
_TIMEOUT_PROTECT_COND
.
wait
()
continue
if
finished
:
continue
now
=
time
.
time
()
wait_time
=
max
(
0
,
_TIMEOUT_PROTECT_WAIT_TIME
-
now
+
when
)
time
.
sleep
(
wait_time
)
with
_TIMEOUT_PROTECT_LOCK
:
if
finished
:
continue
libdokan
.
DokanResetTimeout
(
_TIMEOUT_PROTECT_RESET_TIME
,
info
)
_TIMEOUT_PROTECT_QUEUE
.
append
((
now
+
wait_time
,
info
,
finished
))
def
timeout_protect
(
func
):
def
timeout_protect
(
func
):
"""Method decorator to enable timeout protection during call.
"""Method decorator to enable timeout protection during call.
...
@@ -239,10 +250,13 @@ def timeout_protect(func):
...
@@ -239,10 +250,13 @@ def timeout_protect(func):
info
=
args
[
-
1
]
info
=
args
[
-
1
]
finished
=
[]
finished
=
[]
try
:
try
:
_TIMEOUT_PROTECT_QUEUE
.
put
((
time
.
time
(),
info
,
finished
))
with
_TIMEOUT_PROTECT_COND
:
_TIMEOUT_PROTECT_QUEUE
.
append
((
time
.
time
(),
info
,
finished
))
_TIMEOUT_PROTECT_COND
.
notify
()
return
func
(
self
,
*
args
)
return
func
(
self
,
*
args
)
finally
:
finally
:
finished
.
append
(
True
)
with
_TIMEOUT_PROTECT_LOCK
:
finished
.
append
(
True
)
return
wrapper
return
wrapper
...
...
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