Я пытаюсь запустить скрипт websocket из django
async def get_cells(websocket, path):
async for message in websocket:
message = json.loads(message)
...
if percentage % 5 == 0:
await websocket.send(json.dumps({'complete': False, 'status': percentage}))
...
await websocket.send(json.dumps({'complete': True, 'filename': filename}))
asyncio.get_event_loop (). Run_until_complete (
websockets.serve (get_cells, 'localhost', 8765))
asyncio.get_event_loop (). Run_forever ()
Я сохранил как path.py и импортировал в URL-адресах
import path
Выдает эту ошибку
^C(pixelart) sam@sam-Lenovo-G51-35:~/code/pixelart$ python manage.py runserver
Performing system checks...
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f38e007f1e0>
Traceback (most recent call last):
File "/home/sam/code/envs/pixelart/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "/home/sam/code/envs/pixelart/lib/python3.6/site-packages/django/core/management/commands/runserver.py",line 117, in inner_run
self.check(display_num_errors=True)
File "/home/sam/code/envs/pixelart/lib/python3.6/site-packages/django/core/management/base.py", line 379, in check
include_deployment_checks=include_deployment_checks,
File "/home/sam/code/envs/pixelart/lib/python3.6/site-packages/django/core/management/base.py", line 366, in _run_checks
return checks.run_checks(**kwargs)
File "/home/sam/code/envs/pixelart/lib/python3.6/site-packages/django/core/checks/registry.py", line 71, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/sam/code/envs/pixelart/lib/python3.6/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/home/sam/code/envs/pixelart/lib/python3.6/site-packages/django/core/checks/urls.py", line 23, in check_resolver
return check_method()
File "/home/sam/code/envs/pixelart/lib/python3.6/site-packages/django/urls/resolvers.py", line 396, in check
for pattern in self.url_patterns:
File "/home/sam/code/envs/pixelart/lib/python3.6/site-packages/django/utils/functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/sam/code/envs/pixelart/lib/python3.6/site-packages/django/urls/resolvers.py", line 533, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/sam/code/envs/pixelart/lib/python3.6/site-packages/django/utils/functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/sam/code/envs/pixelart/lib/python3.6/site-packages/django/urls/resolvers.py", line 526, in urlconf_module
return import_module(self.urlconf_name)
File "/home/sam/code/envs/pixelart/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/sam/code/pixelart/pixelart/urls.py", line 7, in <module>
import path
File "/home/sam/code/pixelart/path.py", line 55, in <module>
asyncio.get_event_loop().run_until_complete(
File "/usr/lib/python3.6/asyncio/events.py", line 694, in get_event_loop
return get_event_loop_policy().get_event_loop()
File "/usr/lib/python3.6/asyncio/events.py", line 602, in get_event_loop
% threading.current_thread().name)
RuntimeError: There is no current event loop in thread 'Dummy-1'.
Предложение
loop = asyncio.get_event_loop().run_until_complete(
websockets.serve(get_cells, 'localhost', 8765))
asyncio.get_event_loop(loop).run_forever()
это предложение возвращает ту же ошибку.