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
b0435230
Commit
b0435230
authored
Apr 09, 2018
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add kwargs to patch_all for plugins.
parent
57b465b3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
11 deletions
+42
-11
src/gevent/events.py
src/gevent/events.py
+20
-6
src/gevent/monkey.py
src/gevent/monkey.py
+10
-4
src/greentest/test__monkey.py
src/greentest/test__monkey.py
+12
-1
No files found.
src/gevent/events.py
View file @
b0435230
...
...
@@ -398,7 +398,12 @@ class IGeventWillPatchAllEvent(IGeventWillPatchEvent):
"""
patch_all_arguments
=
Attribute
(
"A dictionary all the arguments to `gevent.monkey.patch_all`. "
"A dictionary of all the arguments to `gevent.monkey.patch_all`. "
"This dictionary should not be modified. "
)
patch_all_kwargs
=
Attribute
(
"A dictionary of the extra arguments to `gevent.monkey.patch_all`. "
"This dictionary should not be modified. "
)
...
...
@@ -408,14 +413,19 @@ class IGeventWillPatchAllEvent(IGeventWillPatchEvent):
"""
class
_PatchAllMixin
(
object
):
def
__init__
(
self
,
patch_all_arguments
):
def
__init__
(
self
,
patch_all_arguments
,
patch_all_kwargs
):
super
(
_PatchAllMixin
,
self
).
__init__
(
None
,
None
)
self
.
_patch_all_arguments
=
patch_all_arguments
self
.
_patch_all_kwargs
=
patch_all_kwargs
@
property
def
patch_all_arguments
(
self
):
return
self
.
_patch_all_arguments
.
copy
()
@
property
def
patch_all_kwargs
(
self
):
return
self
.
_patch_all_kwargs
.
copy
()
def
__repr__
(
self
):
return
'<%s %r at %x>'
%
(
self
.
__class__
.
__name__
,
self
.
_patch_all_arguments
,
...
...
@@ -443,8 +453,15 @@ class IGeventDidPatchBuiltinModulesEvent(IGeventDidPatchEvent):
patch_all_arguments
=
Attribute
(
"A dictionary of all the arguments to `gevent.monkey.patch_all`. "
"This dictionary should not be modified. "
)
patch_all_kwargs
=
Attribute
(
"A dictionary of the extra arguments to `gevent.monkey.patch_all`. "
"This dictionary should not be modified. "
)
@
implementer
(
IGeventDidPatchBuiltinModulesEvent
)
class
GeventDidPatchBuiltinModulesEvent
(
_PatchAllMixin
,
GeventDidPatchEvent
):
"""
Implementation of `IGeventDidPatchBuiltinModulesEvent`.
...
...
@@ -463,7 +480,7 @@ class IGeventDidPatchAllEvent(IGeventDidPatchEvent):
"""
@
implementer
(
IGeventDidPatchAllEvent
)
class
GeventDidPatchAllEvent
(
GeventDidPatchEvent
):
class
GeventDidPatchAllEvent
(
_PatchAllMixin
,
GeventDidPatchEvent
):
"""
Implementation of `IGeventDidPatchAllEvent`.
"""
...
...
@@ -471,6 +488,3 @@ class GeventDidPatchAllEvent(GeventDidPatchEvent):
#: The name of the setuptools entry point that is called when this
#: event is emitted.
ENTRY_POINT_NAME
=
'gevent.plugins.monkey.did_patch_all'
def
__init__
(
self
):
super
(
GeventDidPatchAllEvent
,
self
).
__init__
(
None
,
None
)
src/gevent/monkey.py
View file @
b0435230
...
...
@@ -826,6 +826,7 @@ def patch_signal():
def
_check_repatching
(
**
module_settings
):
_warnings
=
[]
key
=
'_gevent_saved_patch_all'
del
module_settings
[
'kwargs'
]
if
saved
.
get
(
key
,
module_settings
)
!=
module_settings
:
_queue_warning
(
"Patching more than once will result in the union of all True"
" parameters being patched"
,
...
...
@@ -848,7 +849,8 @@ def _subscribe_signal_os(will_patch_all):
def
patch_all
(
socket
=
True
,
dns
=
True
,
time
=
True
,
select
=
True
,
thread
=
True
,
os
=
True
,
ssl
=
True
,
httplib
=
False
,
# Deprecated, to be removed.
subprocess
=
True
,
sys
=
False
,
aggressive
=
True
,
Event
=
True
,
builtins
=
True
,
signal
=
True
):
builtins
=
True
,
signal
=
True
,
**
kwargs
):
"""
Do all of the default monkey patching (calls every other applicable
function in this module).
...
...
@@ -868,6 +870,10 @@ def patch_all(socket=True, dns=True, time=True, select=True, thread=True, os=Tru
``Event`` defaults to True.
.. versionchanged:: 1.3b1
Defined the return values.
.. versionchanged:: 1.3b1
Add ``**kwargs`` for the benefit of event subscribers. CAUTION: gevent may add
and interpret additional arguments in the future, so it is suggested to use prefixes
for kwarg values to be interpreted by plugins, for example, `patch_all(mylib_futures=True)`.
"""
# pylint:disable=too-many-locals,too-many-branches
...
...
@@ -880,7 +886,7 @@ def patch_all(socket=True, dns=True, time=True, select=True, thread=True, os=Tru
from
gevent
import
events
try
:
_notify_patch
(
events
.
GeventWillPatchAllEvent
(
modules_to_patch
),
_warnings
)
_notify_patch
(
events
.
GeventWillPatchAllEvent
(
modules_to_patch
,
kwargs
),
_warnings
)
except
events
.
DoNotPatch
:
return
False
...
...
@@ -910,8 +916,8 @@ def patch_all(socket=True, dns=True, time=True, select=True, thread=True, os=Tru
if
signal
:
patch_signal
()
_notify_patch
(
events
.
GeventDidPatchBuiltinModulesEvent
(
modules_to_patch
),
_warnings
)
_notify_patch
(
events
.
GeventDidPatchAllEvent
(),
_warnings
)
_notify_patch
(
events
.
GeventDidPatchBuiltinModulesEvent
(
modules_to_patch
,
kwargs
),
_warnings
)
_notify_patch
(
events
.
GeventDidPatchAllEvent
(
modules_to_patch
,
kwargs
),
_warnings
)
_process_warnings
(
_warnings
)
return
True
...
...
src/greentest/test__monkey.py
View file @
b0435230
...
...
@@ -70,6 +70,7 @@ class TestMonkey(SubscriberCleanupMixin, unittest.TestCase):
def
test_patch_twice_warnings_events
(
self
):
import
warnings
from
zope.interface
import
verify
orig_saved
=
{}
for
k
,
v
in
monkey
.
saved
.
items
():
...
...
@@ -88,7 +89,7 @@ class TestMonkey(SubscriberCleanupMixin, unittest.TestCase):
with
warnings
.
catch_warnings
(
record
=
True
)
as
issued_warnings
:
# Patch again, triggering three warnings, one for os=False/signal=True,
# one for repeated monkey-patching, one for patching after ssl (on python >= 2.7.9)
monkey
.
patch_all
(
os
=
False
)
monkey
.
patch_all
(
os
=
False
,
extra_kwarg
=
42
)
self
.
assertGreaterEqual
(
len
(
issued_warnings
),
2
)
self
.
assertIn
(
'SIGCHLD'
,
str
(
issued_warnings
[
-
1
].
message
))
self
.
assertIn
(
'more than once'
,
str
(
issued_warnings
[
0
].
message
))
...
...
@@ -114,10 +115,20 @@ class TestMonkey(SubscriberCleanupMixin, unittest.TestCase):
self
.
assertNotIn
(
'gevent'
,
str
(
v
))
self
.
assertIsInstance
(
all_events
[
0
],
events
.
GeventWillPatchAllEvent
)
self
.
assertEqual
({
'extra_kwarg'
:
42
},
all_events
[
0
].
patch_all_kwargs
)
verify
.
verifyObject
(
events
.
IGeventWillPatchAllEvent
,
all_events
[
0
])
self
.
assertIsInstance
(
all_events
[
1
],
events
.
GeventWillPatchModuleEvent
)
verify
.
verifyObject
(
events
.
IGeventWillPatchModuleEvent
,
all_events
[
1
])
self
.
assertIsInstance
(
all_events
[
2
],
events
.
GeventDidPatchModuleEvent
)
verify
.
verifyObject
(
events
.
IGeventWillPatchModuleEvent
,
all_events
[
1
])
self
.
assertIsInstance
(
all_events
[
-
2
],
events
.
GeventDidPatchBuiltinModulesEvent
)
verify
.
verifyObject
(
events
.
IGeventDidPatchBuiltinModulesEvent
,
all_events
[
-
2
])
self
.
assertIsInstance
(
all_events
[
-
1
],
events
.
GeventDidPatchAllEvent
)
verify
.
verifyObject
(
events
.
IGeventDidPatchAllEvent
,
all_events
[
-
1
])
for
e
in
all_events
:
self
.
assertFalse
(
isinstance
(
e
,
events
.
GeventDidPatchModuleEvent
)
...
...
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