Skip to content

Commit

Permalink
Use asyncio.Lock to process one control message at a time
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthomas23 committed Feb 14, 2024
1 parent fb8e192 commit 8ca6219
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions ipykernel/kernelbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,6 @@ def _parent_header(self):
"usage_request",
]

# Flag to ensure a single control request is processed at a time.
_block_control = False

def __init__(self, **kwargs):
"""Initialize the kernel."""
super().__init__(**kwargs)
Expand All @@ -298,17 +295,8 @@ def __init__(self, **kwargs):

async def dispatch_control(self, msg):
# Ensure only one control message is processed at a time
while self._block_control:
await asyncio.sleep(0)

self._block_control = True

try:
async with asyncio.Lock():
await self.process_control(msg)
except:
raise
finally:
self._block_control = False

async def process_control(self, msg):
"""dispatch control requests"""
Expand Down

0 comments on commit 8ca6219

Please sign in to comment.