-
Notifications
You must be signed in to change notification settings - Fork 332
eventlet asyncio hub does not run as documented #929
Copy link
Copy link
Closed
Description
Hi, I am trying to run the examples on the eventlet.net website. I am using eventlet==0.35.2 with Python 3.10.13. I have the same problem with master and Python 3.11.7.
While it is not copied verbatim from the website (that obviously will not run), I think it is very close.
import eventlet
import eventlet.hubs
eventlet.hubs.use_hub("eventlet.hubs.asyncio")
eventlet.monkey_patch()
import aiohttp
from eventlet.asyncio import spawn_for_awaitable
async def request():
async with aiohttp.ClientSession() as session:
url = "https://example.com"
async with session.get(url) as response:
html = await response.text()
return html
# You can wrap this coroutine with an Eventlet GreenThread, similar to
# ``evenlet.spawn()``:
gthread = spawn_for_awaitable(request())
# And then get its result, the body of https://example.com:
result = gthread.wait()
print(result)
This raises an assertion:
Traceback (most recent call last):
File "/Users/yury/workspace/agi/eventlet_asyncio2.py", line 22, in <module>
result = gthread.wait()
File "/Users/yury/.virtualenvs/scratch/lib/python3.10/site-packages/eventlet/greenthread.py", line 224, in wait
return self._exit_event.wait()
File "/Users/yury/.virtualenvs/scratch/lib/python3.10/site-packages/eventlet/event.py", line 124, in wait
result = hub.switch()
File "/Users/yury/.virtualenvs/scratch/lib/python3.10/site-packages/eventlet/hubs/hub.py", line 310, in switch
return self.greenlet.switch()
File "/Users/yury/.virtualenvs/scratch/lib/python3.10/site-packages/eventlet/greenthread.py", line 264, in main
result = function(*args, **kwargs)
File "/Users/yury/.virtualenvs/scratch/lib/python3.10/site-packages/eventlet/asyncio.py", line 54, in _run
return future.result()
File "/Users/yury/workspace/agi/eventlet_asyncio2.py", line 13, in request
async with session.get(url) as response:
File "/Users/yury/.virtualenvs/scratch/lib/python3.10/site-packages/aiohttp/client.py", line 1187, in __aenter__
self._resp = await self._coro
File "/Users/yury/.virtualenvs/scratch/lib/python3.10/site-packages/aiohttp/client.py", line 574, in _request
conn = await self._connector.connect(
File "/Users/yury/.virtualenvs/scratch/lib/python3.10/site-packages/aiohttp/connector.py", line 544, in connect
proto = await self._create_connection(req, traces, timeout)
File "/Users/yury/.virtualenvs/scratch/lib/python3.10/site-packages/aiohttp/connector.py", line 911, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
File "/Users/yury/.virtualenvs/scratch/lib/python3.10/site-packages/aiohttp/connector.py", line 1173, in _create_direct_connection
hosts = await asyncio.shield(host_resolved)
File "/Users/yury/.virtualenvs/scratch/lib/python3.10/site-packages/aiohttp/connector.py", line 884, in _resolve_host
addrs = await self._resolver.resolve(host, port, family=self._family)
File "/Users/yury/.virtualenvs/scratch/lib/python3.10/site-packages/aiohttp/resolver.py", line 33, in resolve
infos = await self._loop.getaddrinfo(
File "/Users/yury/.pyenv/versions/3.10.13/lib/python3.10/asyncio/base_events.py", line 863, in getaddrinfo
return await self.run_in_executor(
File "/Users/yury/.pyenv/versions/3.10.13/lib/python3.10/asyncio/base_events.py", line 821, in run_in_executor
executor.submit(func, *args), loop=self)
File "/Users/yury/.pyenv/versions/3.10.13/lib/python3.10/concurrent/futures/thread.py", line 176, in submit
self._adjust_thread_count()
File "/Users/yury/.pyenv/versions/3.10.13/lib/python3.10/concurrent/futures/thread.py", line 199, in _adjust_thread_count
t.start()
File "/Users/yury/.pyenv/versions/3.10.13/lib/python3.10/threading.py", line 940, in start
self._started.wait()
File "/Users/yury/.pyenv/versions/3.10.13/lib/python3.10/threading.py", line 607, in wait
signaled = self._cond.wait(timeout)
File "/Users/yury/.pyenv/versions/3.10.13/lib/python3.10/threading.py", line 320, in wait
waiter.acquire()
File "/Users/yury/.virtualenvs/scratch/lib/python3.10/site-packages/eventlet/semaphore.py", line 115, in acquire
hubs.get_hub().switch()
File "/Users/yury/.virtualenvs/scratch/lib/python3.10/site-packages/eventlet/hubs/hub.py", line 297, in switch
assert cur is not self.greenlet, 'Cannot switch to MAINLOOP from MAINLOOP'
AssertionError: Cannot switch to MAINLOOP from MAINLOOP
The only real difference between this code and the example code is that I added the monkey-patch line. Am I misunderstanding the example? Is there something else I need to do?
Reactions are currently unavailable