import phasemap as pm
def phase(pos):
x, y = pos
return int(x**2 + y**2 < 1)
res = pm.run(
phase,
limits=[(-1, 1), (-1, 1)],
mesh=3,
)
< /code>
Когда я запускаю этот код (на Python 3.11.9), возникает следующая ошибка: < /p>
File ~/Desktop/repos/non_linear_topological_invariants/nonlinear_topological_invariants/lib/python3.11/site-packages/phasemap-1.0.0-py3.11.egg/phasemap/_run.py:103, in run(fct, limits, mesh, num_steps, all_corners, init_result, save_file, load, load_quiet, serializer, save_interval)
90 else:
91 init_points = None
93 return _RunImpl(
94 fct=fct,
95 limits=limits,
96 mesh=mesh,
97 num_steps=num_steps,
98 all_corners=all_corners,
99 init_points=init_points,
100 save_file=save_file,
101 serializer=serializer,
102 save_interval=save_interval,
--> 103 ).execute()
File ~/Desktop/repos/non_linear_topological_invariants/nonlinear_topological_invariants/lib/python3.11/site-packages/phasemap-1.0.0-py3.11.egg/phasemap/_run.py:158, in _RunImpl.execute(self)
157 def execute(self):
--> 158 self._loop.run_until_complete(self._run())
159 return self.result
File ~/.pyenv/versions/3.11.9/lib/python3.11/asyncio/base_events.py:630, in BaseEventLoop.run_until_complete(self, future)
619 """Run until the Future is done.
620
621 If the argument is a coroutine, it is wrapped in a Task.
(...) 627 Return the Future's result, or raise its exception.
628 """
629 self._check_closed()
--> 630 self._check_running()
632 new_task = not futures.isfuture(future)
633 future = tasks.ensure_future(future, loop=self)
File ~/.pyenv/versions/3.11.9/lib/python3.11/asyncio/base_events.py:589, in BaseEventLoop._check_running(self)
587 def _check_running(self):
588 if self.is_running():
--> 589 raise RuntimeError('This event loop is already running')
590 if events._get_running_loop() is not None:
591 raise RuntimeError(
592 'Cannot run the event loop while another loop is running')
RuntimeError: This event loop is already running
Это кажется простой проблемой с реализацией библиотеки Asyncio , но я не знаю, как ее исправить. Есть ли прямое исправление в этом пакете, которое решит проблему?
Спасибо!
File ~/.pyenv/versions/3.11.9/lib/python3.11/asyncio/base_events.py:630, in BaseEventLoop.run_until_complete(self, future) 619 """Run until the Future is done. 620 621 If the argument is a coroutine, it is wrapped in a Task. (...) 627 Return the Future's result, or raise its exception. 628 """ 629 self._check_closed() --> 630 self._check_running() 632 new_task = not futures.isfuture(future) 633 future = tasks.ensure_future(future, loop=self)
File ~/.pyenv/versions/3.11.9/lib/python3.11/asyncio/base_events.py:589, in BaseEventLoop._check_running(self) 587 def _check_running(self): 588 if self.is_running(): --> 589 raise RuntimeError('This event loop is already running') 590 if events._get_running_loop() is not None: 591 raise RuntimeError( 592 'Cannot run the event loop while another loop is running')
RuntimeError: This event loop is already running [/code] Это кажется простой проблемой с реализацией библиотеки Asyncio , но я не знаю, как ее исправить. Есть ли прямое исправление в этом пакете, которое решит проблему? Спасибо!
Использование Async/wait было представлено в Flask 2.0. ( await в RESTX Запрашивает обработчики?
Что -то вроде:
@api.route('/try-async')
class MyResource(Resource):
@api.expect(some_schema)
async def get(self):
result = await async_function()...
Когда мы используем асинхронные контекстные менеджеры и итераторы в Python, я не вижу в них никакой пользы. Потому что в диспетчере контекста при вызове aenter () и aexit () они становятся единственными задачами, доступными в цикле событий....