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
b098197a
Commit
b098197a
authored
Mar 10, 2016
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup monkey.
parent
2ce1fd3c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
26 deletions
+31
-26
gevent/monkey.py
gevent/monkey.py
+28
-26
gevent/socket.py
gevent/socket.py
+3
-0
No files found.
gevent/monkey.py
View file @
b098197a
...
...
@@ -80,14 +80,11 @@ if sys.version_info[0] >= 3:
string_types
=
str
,
PY3
=
True
else
:
import
__builtin__
import
__builtin__
# pylint:disable=import-error
string_types
=
__builtin__
.
basestring
PY3
=
False
if
sys
.
platform
.
startswith
(
"win"
):
WIN
=
True
else
:
WIN
=
False
WIN
=
sys
.
platform
.
startswith
(
"win"
)
# maps module name -> {attribute name: original item}
# e.g. "time" -> {"sleep": built-in function sleep}
...
...
@@ -133,19 +130,19 @@ def get_original(mod_name, item_name):
else
:
return
_get_original
(
mod_name
,
item_name
)
_NONE
=
object
()
def
patch_item
(
module
,
attr
,
newitem
):
NONE
=
object
()
olditem
=
getattr
(
module
,
attr
,
NONE
)
if
olditem
is
not
NONE
:
olditem
=
getattr
(
module
,
attr
,
_NONE
)
if
olditem
is
not
_NONE
:
saved
.
setdefault
(
module
.
__name__
,
{}).
setdefault
(
attr
,
olditem
)
setattr
(
module
,
attr
,
newitem
)
def
remove_item
(
module
,
attr
):
NONE
=
object
()
olditem
=
getattr
(
module
,
attr
,
NONE
)
if
olditem
is
NONE
:
olditem
=
getattr
(
module
,
attr
,
_NONE
)
if
olditem
is
_NONE
:
return
saved
.
setdefault
(
module
.
__name__
,
{}).
setdefault
(
attr
,
olditem
)
delattr
(
module
,
attr
)
...
...
@@ -294,6 +291,9 @@ def patch_thread(threading=True, _threading_local=True, Event=False, logging=Tru
.. versionchanged:: 1.1b1
Add *logging* and *existing_locks* params.
"""
# XXX: Simplify
# pylint:disable=too-many-branches
# Description of the hang:
# There is an incompatibility with patching 'thread' and the 'multiprocessing' module:
# The problem is that multiprocessing.queues.Queue uses a half-duplex multiprocessing.Pipe,
...
...
@@ -326,18 +326,18 @@ def patch_thread(threading=True, _threading_local=True, Event=False, logging=Tru
patch_module
(
'thread'
)
if
threading
:
threading
=
patch_module
(
'threading'
)
threading
_mod
=
patch_module
(
'threading'
)
if
Event
:
from
gevent.event
import
Event
patch_item
(
threading
,
'Event'
,
Event
)
patch_item
(
threading
_mod
,
'Event'
,
Event
)
if
existing_locks
:
_patch_existing_locks
(
threading
)
_patch_existing_locks
(
threading
_mod
)
if
logging
and
'logging'
in
sys
.
modules
:
logging
=
__import__
(
'logging'
)
patch_item
(
logging
,
'_lock'
,
threading
.
RLock
())
patch_item
(
logging
,
'_lock'
,
threading
_mod
.
RLock
())
for
wr
in
logging
.
_handlerList
:
# In py26, these are actual handlers, not weakrefs
handler
=
wr
()
if
callable
(
wr
)
else
wr
...
...
@@ -345,7 +345,7 @@ def patch_thread(threading=True, _threading_local=True, Event=False, logging=Tru
continue
if
not
hasattr
(
handler
,
'lock'
):
raise
TypeError
(
"Unknown/unsupported handler %r"
%
handler
)
handler
.
lock
=
threading
.
RLock
()
handler
.
lock
=
threading
_mod
.
RLock
()
if
_threading_local
:
_threading_local
=
__import__
(
'_threading_local'
)
...
...
@@ -359,15 +359,15 @@ def patch_thread(threading=True, _threading_local=True, Event=False, logging=Tru
# (which is already running) cannot wait for the main thread---it
# hangs forever. We patch around this if possible. See also
# gevent.threading.
threading
=
__import__
(
'threading'
)
threading
_mod
=
__import__
(
'threading'
)
greenlet
=
__import__
(
'greenlet'
)
if
threading
.
current_thread
()
==
threading
.
main_thread
():
main_thread
=
threading
.
main_thread
()
if
threading
_mod
.
current_thread
()
==
threading_mod
.
main_thread
():
main_thread
=
threading
_mod
.
main_thread
()
_greenlet
=
main_thread
.
_greenlet
=
greenlet
.
getcurrent
()
from
gevent.hub
import
sleep
def
join
(
timeout
=
None
):
if
threading
.
current_thread
()
is
main_thread
:
if
threading
_mod
.
current_thread
()
is
main_thread
:
raise
RuntimeError
(
"Cannot join current thread"
)
if
_greenlet
.
dead
or
not
main_thread
.
is_alive
():
return
...
...
@@ -384,11 +384,11 @@ def patch_thread(threading=True, _threading_local=True, Event=False, logging=Tru
# matters if threading was imported before monkey-patching
# thread
oldid
=
main_thread
.
ident
main_thread
.
_ident
=
threading
.
get_ident
()
if
oldid
in
threading
.
_active
:
threading
.
_active
[
main_thread
.
ident
]
=
threading
.
_active
[
oldid
]
main_thread
.
_ident
=
threading
_mod
.
get_ident
()
if
oldid
in
threading
_mod
.
_active
:
threading
_mod
.
_active
[
main_thread
.
ident
]
=
threading_mod
.
_active
[
oldid
]
if
oldid
!=
main_thread
.
ident
:
del
threading
.
_active
[
oldid
]
del
threading
_mod
.
_active
[
oldid
]
else
:
_queue_warning
(
"Monkey-patching not on the main thread; "
"threading.main_thread().join() will hang from a greenlet"
,
...
...
@@ -471,7 +471,7 @@ def patch_select(aggressive=True):
select
=
__import__
(
'select'
)
selectors
=
__import__
(
'selectors'
)
if
selectors
.
SelectSelector
.
_select
is
select
.
select
:
def
_select
(
self
,
*
args
,
**
kwargs
):
def
_select
(
self
,
*
args
,
**
kwargs
):
# pylint:disable=unused-argument
return
select
.
select
(
*
args
,
**
kwargs
)
selectors
.
SelectSelector
.
_select
=
_select
...
...
@@ -555,6 +555,8 @@ def patch_all(socket=True, dns=True, time=True, select=True, thread=True, os=Tru
and ``signal=True``. This will cause SIGCHLD handlers to not be called. This may
be an error in the future.
"""
# pylint:disable=too-many-locals,too-many-branches
# Check to see if they're changing the patched list
_warnings
,
first_time
=
_check_repatching
(
**
locals
())
if
not
_warnings
and
not
first_time
:
...
...
@@ -640,7 +642,7 @@ def main():
def
_get_script_help
():
from
inspect
import
getargspec
patch_all_args
=
getargspec
(
patch_all
)[
0
]
patch_all_args
=
getargspec
(
patch_all
)[
0
]
# pylint:disable=deprecated-method
modules
=
[
x
for
x
in
patch_all_args
if
'patch_'
+
x
in
globals
()]
script_help
=
"""gevent.monkey - monkey patch the standard modules to use gevent.
...
...
gevent/socket.py
View file @
b098197a
...
...
@@ -22,6 +22,9 @@ if PY3:
else
:
from
gevent
import
_socket2
as
_source
# define some things we're expecting to overwrite; each module
# needs to define these
__implements__
=
__dns__
=
__all__
=
__extensions__
=
__imports__
=
()
for
key
in
_source
.
__dict__
:
if
key
.
startswith
(
'__'
)
and
key
not
in
'__implements__ __dns__ __all__ __extensions__ __imports__ __socket__'
.
split
():
...
...
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