Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tango
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LOFAR2.0
tango
Commits
d5825d08
Commit
d5825d08
authored
3 years ago
by
Jan David Mol
Browse files
Options
Downloads
Plain Diff
Merge branch '
L2SS-560
-avoid-asyncio-race-condition' into 'master'
L2SS-560
: Avoid race condition in asyncio.all_tasks Closes
L2SS-560
See merge request
!212
parents
89bc8d43
35047af2
No related branches found
No related tags found
1 merge request
!212
L2SS-560: Avoid race condition in asyncio.all_tasks
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tangostationcontrol/tangostationcontrol/clients/tcp_replicator.py
+23
-1
23 additions, 1 deletion
...tioncontrol/tangostationcontrol/clients/tcp_replicator.py
with
23 additions
and
1 deletion
tangostationcontrol/tangostationcontrol/clients/tcp_replicator.py
+
23
−
1
View file @
d5825d08
...
@@ -4,6 +4,7 @@ from threading import Semaphore
...
@@ -4,6 +4,7 @@ from threading import Semaphore
from
threading
import
Thread
from
threading
import
Thread
import
asyncio
import
asyncio
import
logging
import
logging
import
sys
from
tangostationcontrol.clients.statistics_client_thread
import
StatisticsClientThread
from
tangostationcontrol.clients.statistics_client_thread
import
StatisticsClientThread
...
@@ -351,4 +352,25 @@ class TCPReplicator(Thread, StatisticsClientThread):
...
@@ -351,4 +352,25 @@ class TCPReplicator(Thread, StatisticsClientThread):
def
nof_tasks_pending
(
self
):
def
nof_tasks_pending
(
self
):
"""
Return the number of pending tasks in our event loop.
"""
"""
Return the number of pending tasks in our event loop.
"""
# asyncio.all_tasks is not thread safe, and can fail on a race condition if another
# thread adds a task to a different loop while we're in all_tasks().
# We thus occasionally need to retry. We try a limited number of times to avoid
# infinite loops.
#
# See https://bugs.python.org/issue36607 and https://support.astron.nl/jira/browse/L2SS-560
#
# This is fixed (in a similar manner as here) in python 3.7.4+, see
# https://github.com/python/cpython/blob/v3.7.3/Lib/asyncio/tasks.py#L34
# versus
# https://github.com/python/cpython/blob/v3.7.4/Lib/asyncio/tasks.py#L34
if
sys
.
version_info
>=
(
3
,
7
,
4
):
return
asyncio
.
all_tasks
(
self
.
_loop
)
else
:
for
i
in
range
(
100
,
0
,
-
1
):
try
:
return
len
(
asyncio
.
all_tasks
(
self
.
_loop
))
return
len
(
asyncio
.
all_tasks
(
self
.
_loop
))
except
RuntimeError
as
e
:
if
i
==
1
:
# ran out of tries, and we want to expose the original exception
raise
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment