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
e973d814
Commit
e973d814
authored
Sep 29, 2012
by
Denis Bilenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FileObjectThread: synchronize calls with semaphore
parent
6e968707
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
3 deletions
+15
-3
gevent/fileobject.py
gevent/fileobject.py
+15
-3
No files found.
gevent/fileobject.py
View file @
e973d814
from
__future__
import
absolute_import
from
__future__
import
absolute_import
,
with_statement
import
sys
import
os
from
gevent.hub
import
get_hub
from
gevent.socket
import
EBADF
from
gevent.os
import
_read
,
_write
,
ignored_errors
from
gevent.lock
import
Semaphore
,
DummySemaphore
try
:
...
...
@@ -215,8 +216,15 @@ class FileObjectThread(object):
def
__init__
(
self
,
fobj
,
*
args
,
**
kwargs
):
self
.
_close
=
kwargs
.
pop
(
'close'
,
True
)
self
.
threadpool
=
kwargs
.
pop
(
'threadpool'
,
None
)
self
.
lock
=
kwargs
.
pop
(
'lock'
,
True
)
if
kwargs
:
raise
TypeError
(
'Unexpected arguments: %r'
%
kwargs
.
keys
())
if
self
.
lock
is
True
:
self
.
lock
=
Semaphore
()
elif
not
self
.
lock
:
self
.
lock
=
DummySemaphore
()
if
not
hasattr
(
self
.
lock
,
'__enter__'
):
raise
TypeError
(
'Expected a Semaphore or boolean, got %r'
%
type
(
self
.
lock
))
if
isinstance
(
fobj
,
(
int
,
long
)):
if
not
self
.
_close
:
# we cannot do this, since fdopen object will close the descriptor
...
...
@@ -226,6 +234,10 @@ class FileObjectThread(object):
if
self
.
threadpool
is
None
:
self
.
threadpool
=
get_hub
().
threadpool
def
_apply
(
self
,
func
,
args
=
None
,
kwargs
=
None
):
with
self
.
lock
:
return
self
.
threadpool
.
apply_e
(
BaseException
,
func
,
args
,
kwargs
)
def
close
(
self
):
fobj
=
self
.
_fobj
if
fobj
is
None
:
...
...
@@ -244,7 +256,7 @@ class FileObjectThread(object):
fobj
=
self
.
_fobj
if
fobj
is
None
:
raise
FileObjectClosed
return
self
.
threadpool
.
apply_e
(
BaseException
,
fobj
.
flush
)
return
self
.
_apply
(
fobj
.
flush
)
def
__repr__
(
self
):
return
'<%s _fobj=%r threadpool=%r>'
%
(
self
.
__class__
.
__name__
,
self
.
_fobj
,
self
.
threadpool
)
...
...
@@ -261,7 +273,7 @@ class FileObjectThread(object):
fobj = self._fobj
if fobj is None:
raise FileObjectClosed
return self.
threadpool.apply_e(BaseException,
fobj.%s, args, kwargs)'''
%
(
method
,
method
)
return self.
_apply(
fobj.%s, args, kwargs)'''
%
(
method
,
method
)
def
__iter__
(
self
):
return
self
...
...
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