Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#506 anyio integration #507

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions janus/__init__.py
@@ -1,3 +1,4 @@
import anyio
import asyncio
import sys
import threading
Expand All @@ -7,7 +8,7 @@
from heapq import heappop, heappush
from queue import Empty as SyncQueueEmpty
from queue import Full as SyncQueueFull
from typing import Any, Callable, Deque, Generic, List, Optional, Set, TypeVar
from typing import Any, Callable, Deque, Generic, List, Optional, Set, TypeVar # noqa F401

from typing_extensions import Protocol

Expand Down Expand Up @@ -223,14 +224,16 @@ def f() -> None:
with self._sync_mutex:
self._sync_not_empty.notify()

self._loop.run_in_executor(None, f)
asyncio.ensure_future(anyio.to_thread.run_sync(f, *[]))
# self._loop.run_in_executor(None, f)

def _notify_sync_not_full(self) -> None:
def f() -> None:
with self._sync_mutex:
self._sync_not_full.notify()

fut = asyncio.ensure_future(self._loop.run_in_executor(None, f))
fut = asyncio.ensure_future(anyio.to_thread.run_sync(f, *[]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think there is any interest to support anyio between maintainers, this is asyncio library after all. I do not have experience with it, but may be anyio can provide custom executor so self._loop.run_in_executor can call anyio.to_thread.run_sync(f, *[]) ? Then there is not need to change library itself much, other then may be provide executor for the loop.

# fut = asyncio.ensure_future(self._loop.run_in_executor(None, f))
fut.add_done_callback(self._pending.discard)
self._pending.add(fut)

Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Expand Up @@ -48,6 +48,7 @@ include_package_data = True

install_requires =
typing-extensions>=3.7.4.3
anyio>=3.6.2

[flake8]
exclude = .git,.env,__pycache__,.eggs
Expand Down