Problems with channel redis layer in tutorial part 2
apollo13 opened this issue · comments
https://channels.readthedocs.io/en/latest/tutorial/part_2.html says to execute:
$ python3 manage.py shell
>>> import channels.layers
>>> channel_layer = channels.layers.get_channel_layer()
>>> from asgiref.sync import async_to_sync
>>> async_to_sync(channel_layer.send)('test_channel', {'type': 'hello'})
>>> async_to_sync(channel_layer.receive)('test_channel')
{'type': 'hello'}
to test communication with redis. Running this against Python 3.10; daphne, channels & asgiref from git master results in:
Traceback (most recent call last):
File "/home/florian/sources/async/mysite/./manage.py", line 22, in <module>
main()
File "/home/florian/sources/async/mysite/./manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/florian/sources/django.git/django/core/management/__init__.py", line 425, in execute_from_command_line
utility.execute()
File "/home/florian/sources/django.git/django/core/management/__init__.py", line 419, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/florian/sources/django.git/django/core/management/base.py", line 363, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/florian/sources/django.git/django/core/management/base.py", line 407, in execute
output = self.handle(*args, **options)
File "/home/florian/sources/django.git/django/core/management/commands/shell.py", line 105, in handle
exec(sys.stdin.read(), globals())
File "<string>", line 4, in <module>
File "/home/florian/sources/async/asgiref/asgiref/sync.py", line 225, in __call__
return call_result.result()
File "/usr/lib64/python3.10/concurrent/futures/_base.py", line 438, in result
return self.__get_result()
File "/usr/lib64/python3.10/concurrent/futures/_base.py", line 390, in __get_result
raise self._exception
File "/home/florian/sources/async/asgiref/asgiref/sync.py", line 294, in main_wrap
result = await self.awaitable(*args, **kwargs)
File "/home/florian/.local/share/virtualenvs/async/lib/python3.10/site-packages/channels_redis/core.py", line 343, in send
async with self.connection(index) as connection:
File "/home/florian/.local/share/virtualenvs/async/lib/python3.10/site-packages/channels_redis/core.py", line 902, in __aenter__
self.conn = await self.pool.pop()
File "/home/florian/.local/share/virtualenvs/async/lib/python3.10/site-packages/channels_redis/core.py", line 93, in pop
conn = await self.create_conn(loop)
File "/home/florian/.local/share/virtualenvs/async/lib/python3.10/site-packages/channels_redis/core.py", line 79, in create_conn
return await aioredis.create_redis_pool(**kwargs)
File "/home/florian/.local/share/virtualenvs/async/lib/python3.10/site-packages/aioredis/commands/__init__.py", line 188, in create_redis_pool
pool = await create_pool(address, db=db,
File "/home/florian/.local/share/virtualenvs/async/lib/python3.10/site-packages/aioredis/pool.py", line 51, in create_pool
pool = cls(address, db, password, encoding,
File "/home/florian/.local/share/virtualenvs/async/lib/python3.10/site-packages/aioredis/pool.py", line 95, in __init__
self._cond = asyncio.Condition(lock=Lock())
File "/usr/lib64/python3.10/asyncio/locks.py", line 234, in __init__
raise ValueError("loop argument must agree with lock")
ValueError: loop argument must agree with lock
Looks like we got more than one loop here :/ Gotta figure out where they come from.
This is bpo-45416 and fixed in Python 3.10.1 (broken in 3.10.0)
Also came up in django/channels_redis#278