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
6f9e51fe
Commit
6f9e51fe
authored
Mar 20, 2018
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Killing the monitoring thread should restore the greenlet trace function.
parent
fcfc9304
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
7 deletions
+22
-7
src/gevent/hub.py
src/gevent/hub.py
+13
-6
src/greentest/test__hub.py
src/greentest/test__hub.py
+9
-1
No files found.
src/gevent/hub.py
View file @
6f9e51fe
...
@@ -468,7 +468,7 @@ class PeriodicMonitoringThread(object):
...
@@ -468,7 +468,7 @@ class PeriodicMonitoringThread(object):
# The trace function that was previously installed,
# The trace function that was previously installed,
# if any.
# if any.
previous_trace_function
=
staticmethod
(
lambda
_event
,
_args
:
None
)
previous_trace_function
=
None
# The absolute minimum we will sleep, regardless of
# The absolute minimum we will sleep, regardless of
# what particular monitoring functions want to say.
# what particular monitoring functions want to say.
...
@@ -485,7 +485,7 @@ class PeriodicMonitoringThread(object):
...
@@ -485,7 +485,7 @@ class PeriodicMonitoringThread(object):
# the trace function is threadlocal
# the trace function is threadlocal
assert
get_thread_ident
()
==
hub
.
thread_ident
assert
get_thread_ident
()
==
hub
.
thread_ident
prev_trace
=
settrace
(
self
.
greenlet_trace
)
prev_trace
=
settrace
(
self
.
greenlet_trace
)
self
.
previous_trace_function
=
prev_trace
or
self
.
previous_trace_function
self
.
previous_trace_function
=
prev_trace
# Create the actual monitoring thread. This is effectively a "daemon"
# Create the actual monitoring thread. This is effectively a "daemon"
# thread.
# thread.
...
@@ -500,7 +500,8 @@ class PeriodicMonitoringThread(object):
...
@@ -500,7 +500,8 @@ class PeriodicMonitoringThread(object):
self
.
_active_greenlet
=
args
[
1
]
self
.
_active_greenlet
=
args
[
1
]
else
:
else
:
self
.
_active_greenlet
=
None
self
.
_active_greenlet
=
None
self
.
previous_trace_function
(
event
,
args
)
if
self
.
previous_trace_function
is
not
None
:
self
.
previous_trace_function
(
event
,
args
)
def
monitoring_functions
(
self
):
def
monitoring_functions
(
self
):
# Return a list of tuples: [(function, period)]
# Return a list of tuples: [(function, period)]
...
@@ -521,6 +522,8 @@ class PeriodicMonitoringThread(object):
...
@@ -521,6 +522,8 @@ class PeriodicMonitoringThread(object):
def
kill
(
self
):
def
kill
(
self
):
# Stop this monitoring thread from running.
# Stop this monitoring thread from running.
self
.
should_run
=
False
self
.
should_run
=
False
# Uninstall our tracing hook
settrace
(
self
.
previous_trace_function
)
def
__call__
(
self
):
def
__call__
(
self
):
# The function that runs in the monitoring thread.
# The function that runs in the monitoring thread.
...
@@ -539,9 +542,13 @@ class PeriodicMonitoringThread(object):
...
@@ -539,9 +542,13 @@ class PeriodicMonitoringThread(object):
# Make sure the hub is still around, and still active,
# Make sure the hub is still around, and still active,
# and keep it around while we are here.
# and keep it around while we are here.
hub
=
self
.
_hub_wref
()
hub
=
self
.
_hub_wref
()
if
hub
and
self
.
should_run
:
if
not
hub
:
for
f
,
_
in
functions
:
self
.
kill
()
f
(
hub
)
if
self
.
should_run
:
for
f
,
period
in
functions
:
if
period
:
f
(
hub
)
except
SystemExit
:
except
SystemExit
:
pass
pass
except
:
# pylint:disable=bare-except
except
:
# pylint:disable=bare-except
...
...
src/greentest/test__hub.py
View file @
6f9e51fe
...
@@ -176,12 +176,20 @@ class TestPeriodicMonitoringThread(greentest.TestCase):
...
@@ -176,12 +176,20 @@ class TestPeriodicMonitoringThread(greentest.TestCase):
before_funs
=
monitor
.
_additional_monitoring_functions
before_funs
=
monitor
.
_additional_monitoring_functions
monitor
.
add_monitoring_function
(
monitor
.
add_monitoring_function
(
monitor_cond
,
monitor_cond
,
0
)
0
.01
)
cond
.
wait
()
cond
.
wait
()
cond
.
release
()
cond
.
release
()
monitor
.
_additional_monitoring_functions
=
before_funs
monitor
.
_additional_monitoring_functions
=
before_funs
@
greentest
.
ignores_leakcheck
def
test_kill_removes_trace
(
self
):
from
greenlet
import
gettrace
hub
=
get_hub
()
hub
.
start_periodic_monitoring_thread
()
self
.
assertIsNotNone
(
gettrace
())
hub
.
periodic_monitoring_thread
.
kill
()
self
.
assertIsNone
(
gettrace
())
@
greentest
.
ignores_leakcheck
@
greentest
.
ignores_leakcheck
def
test_blocking_this_thread
(
self
):
def
test_blocking_this_thread
(
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