From a6227af6f7ce8be2f96edc9c379257878ea0342a Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 24 Oct 2021 04:08:04 -0700 Subject: [PATCH] Fix compatibility with Python 3.10, refs #358 (#359) Co-authored-by: Andrew Svetlov --- .github/workflows/ci.yml | 2 +- janus/__init__.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0f96568..5a89ac2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,7 +43,7 @@ jobs: needs: lint strategy: matrix: - python-version: [3.6, 3.7, 3.8, 3.9] + python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"] os: [ubuntu] fail-fast: false diff --git a/janus/__init__.py b/janus/__init__.py index 789f12f..c29c23e 100644 --- a/janus/__init__.py +++ b/janus/__init__.py @@ -1,4 +1,5 @@ import asyncio +import sys import threading from asyncio import QueueEmpty as AsyncQueueEmpty from asyncio import QueueFull as AsyncQueueFull @@ -36,6 +37,9 @@ def __init__(self, maxsize: int = 0) -> None: self._all_tasks_done = threading.Condition(self._sync_mutex) self._async_mutex = asyncio.Lock() + if sys.version_info[:3] == (3, 10, 0): + # Workaround for Python 3.10 bug, see #358: + getattr(self._async_mutex, '_get_loop', lambda: None)() self._async_not_empty = asyncio.Condition(self._async_mutex) self._async_not_full = asyncio.Condition(self._async_mutex) self._finished = asyncio.Event()