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
d2a6b131
Commit
d2a6b131
authored
Jun 15, 2017
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extra test for patching not on main thread.
parent
ac94f486
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
1 deletion
+60
-1
src/gevent/threading.py
src/gevent/threading.py
+1
-1
src/greentest/test__threading_monkey_in_thread.py
src/greentest/test__threading_monkey_in_thread.py
+59
-0
No files found.
src/gevent/threading.py
View file @
d2a6b131
...
...
@@ -217,7 +217,7 @@ def _gevent_will_monkey_patch(native_module, items, warn): # pylint:disable=unus
main_thread
=
main_native_thread
()
if
__threading__
.
current_thread
()
!=
main_thread
:
warn
(
"Monkey-patching outside the main native thread. Some APIs "
"will not be available."
)
"will not be available.
Expect a KeyError to be printed at shutdown.
"
)
return
if
_get_ident
()
not
in
__threading__
.
_active
:
...
...
src/greentest/test__threading_monkey_in_thread.py
0 → 100644
View file @
d2a6b131
# We can monkey-patch in a thread, but things don't work as expected.
import
sys
import
threading
from
gevent
import
monkey
import
greentest
class
Test
(
greentest
.
TestCase
):
def
test_patch_in_thread
(
self
):
all_warnings
=
[]
try
:
get_ident
=
threading
.
get_ident
except
AttributeError
:
get_ident
=
threading
.
_get_ident
def
process_warnings
(
warnings
):
all_warnings
.
extend
(
warnings
)
monkey
.
_process_warnings
=
process_warnings
current
=
threading
.
current_thread
()
current_id
=
get_ident
()
def
target
():
tcurrent
=
threading
.
current_thread
()
monkey
.
patch_all
()
tcurrent2
=
threading
.
current_thread
()
self
.
assertIsNot
(
tcurrent
,
current
)
# We get a dummy thread now
self
.
assertIsNot
(
tcurrent
,
tcurrent2
)
thread
=
threading
.
Thread
(
target
=
target
)
thread
.
start
()
thread
.
join
()
self
.
assertFalse
(
isinstance
(
current
,
threading
.
_DummyThread
))
self
.
assertTrue
(
isinstance
(
current
,
monkey
.
get_original
(
'threading'
,
'Thread'
)))
# We generated some warnings
if
sys
.
version_info
>=
(
3
,
4
):
self
.
assertEqual
(
all_warnings
,
[
'Monkey-patching outside the main native thread. Some APIs will not be '
'available. Expect a KeyError to be printed at shutdown.'
,
'Monkey-patching not on the main thread; threading.main_thread().join() '
'will hang from a greenlet'
])
else
:
self
.
assertEqual
(
all_warnings
,
[
'Monkey-patching outside the main native thread. Some APIs will not be '
'available. Expect a KeyError to be printed at shutdown.'
])
# Manual clean up so we don't get a KeyError
del
threading
.
_active
[
current_id
]
threading
.
_active
[(
getattr
(
threading
,
'get_ident'
,
None
)
or
threading
.
_get_ident
)()]
=
current
if
__name__
==
'__main__'
:
greentest
.
main
()
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