Skip to content

Commit

Permalink
Add assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
x42005e1f authored Dec 11, 2024
1 parent 6d1b8a7 commit 4c0c964
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions janus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def close(self) -> None:
for fut in self._pending:
fut.cancel()
if self._async_tasks_done_waiting:
assert self._loop is not None
self._call_soon_threadsafe( # unblocks all async_q.join()
self._make_async_tasks_done_notifier, self._loop
)
Expand Down Expand Up @@ -280,6 +281,7 @@ def task_done(self) -> None:
if parent._sync_tasks_done_waiting:
parent._sync_tasks_done.notify_all()
if parent._async_tasks_done_waiting:
assert parent._loop is not None
parent._call_soon_threadsafe(
parent._make_async_tasks_done_notifier, parent._loop
)
Expand Down Expand Up @@ -380,10 +382,10 @@ def put(self, item: T, block: bool = True, timeout: OptFloat = None) -> None:
if parent._sync_not_empty_waiting:
parent._sync_not_empty.notify()
if parent._async_not_empty_waiting:
if parent._loop is not None:
parent._call_soon_threadsafe(
parent._make_async_not_empty_notifier, parent._loop
)
assert parent._loop is not None
parent._call_soon_threadsafe(
parent._make_async_not_empty_notifier, parent._loop
)

def get(self, block: bool = True, timeout: OptFloat = None) -> T:
"""Remove and return an item from the queue.
Expand Down Expand Up @@ -426,10 +428,10 @@ def get(self, block: bool = True, timeout: OptFloat = None) -> T:
if parent._sync_not_full_waiting:
parent._sync_not_full.notify()
if parent._async_not_full_waiting:
if parent._loop is not None:
parent._call_soon_threadsafe(
parent._make_async_not_full_notifier, parent._loop
)
assert parent._loop is not None
parent._call_soon_threadsafe(
parent._make_async_not_full_notifier, parent._loop
)
return item

def put_nowait(self, item: T) -> None:
Expand Down Expand Up @@ -635,6 +637,7 @@ def task_done(self) -> None:
parent._unfinished_tasks -= 1
if parent._unfinished_tasks == 0:
if parent._async_tasks_done_waiting:
assert parent._loop is not None
parent._call_soon_threadsafe(
parent._make_async_tasks_done_notifier, parent._loop
)
Expand Down

0 comments on commit 4c0c964

Please sign in to comment.