Proxy-object for an asyncio Any coroutine methods will be wrapped in event_loop.run_
| 62 | |
| 63 | |
| 64 | class _AsyncIOProxy: |
| 65 | """Proxy-object for an asyncio |
| 66 | |
| 67 | Any coroutine methods will be wrapped in event_loop.run_ |
| 68 | """ |
| 69 | |
| 70 | def __init__(self, obj, event_loop): |
| 71 | self._obj = obj |
| 72 | self._event_loop = event_loop |
| 73 | |
| 74 | def __repr__(self): |
| 75 | return f"<_AsyncIOProxy({self._obj!r})>" |
| 76 | |
| 77 | def __getattr__(self, key): |
| 78 | attr = getattr(self._obj, key) |
| 79 | if inspect.iscoroutinefunction(attr): |
| 80 | # if it's a coroutine method, |
| 81 | # return a threadsafe wrapper onto the _current_ asyncio loop |
| 82 | @wraps(attr) |
| 83 | def _wrapped(*args, **kwargs): |
| 84 | concurrent_future = asyncio.run_coroutine_threadsafe( |
| 85 | attr(*args, **kwargs), self._event_loop |
| 86 | ) |
| 87 | return asyncio.wrap_future(concurrent_future) |
| 88 | |
| 89 | return _wrapped |
| 90 | else: |
| 91 | return attr |
| 92 | |
| 93 | def __dir__(self): |
| 94 | return dir(self._obj) |
| 95 | |
| 96 | |
| 97 | def _curio_runner(coroutine): |
no outgoing calls
no test coverage detected
searching dependent graphs…