Skip to content

Commit

Permalink
Shield internal block procedures from cancellation
Browse files Browse the repository at this point in the history
due to connection close() (that the Monitor triggers) because of any
connection issues on the underlying websocket.
  • Loading branch information
cderici committed Sep 6, 2023
1 parent c526d17 commit 0b8912a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion juju/jasyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
gather, sleep, wait_for, create_subprocess_exec, subprocess, \
wait, FIRST_COMPLETED, Lock, as_completed, new_event_loop, \
get_event_loop_policy, CancelledError, get_running_loop, \
create_task, ALL_COMPLETED, all_tasks, current_task # noqa
create_task, ALL_COMPLETED, all_tasks, current_task, shield # noqa


def create_task_with_handler(coro, task_name, logger=ROOT_LOGGER):
Expand Down
4 changes: 2 additions & 2 deletions juju/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async def block_until(*conditions, timeout=None, wait_period=0.5):
async def _block():
while not all(c() for c in conditions):
await jasyncio.sleep(wait_period)
await jasyncio.wait_for(_block(), timeout)
await jasyncio.shield(jasyncio.wait_for(_block(), timeout))


async def block_until_with_coroutine(condition_coroutine, timeout=None, wait_period=0.5):
Expand All @@ -139,7 +139,7 @@ async def block_until_with_coroutine(condition_coroutine, timeout=None, wait_per
async def _block():
while not await condition_coroutine():
await jasyncio.sleep(wait_period)
await jasyncio.wait_for(_block(), timeout=timeout)
await jasyncio.shield(jasyncio.wait_for(_block(), timeout=timeout))


async def wait_for_bundle(model, bundle, **kwargs):
Expand Down

0 comments on commit 0b8912a

Please sign in to comment.