Мне нужно написать функцию через Tornado async / await в моем проекте, но, к сожалению, я столкнулся со странной проблемой в JupyterLab.Я могу показать эту проблему на небольшом примере:
async def divide(x, y):
return x / y
async def call():
# This should raise a ZeroDivisionError, but it won't because
# the coroutine is called incorrectly.
await divide(1, 0)
if __name__ == '__main__':
tornado.ioloop.IOLoop.current().run_sync(call)
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-25-456ba9fee391> in <module>()
8
9 if __name__ == '__main__':
---> 10 tornado.ioloop.IOLoop.current().run_sync(call)
/usr/local/lib/python3.6/site-packages/tornado/ioloop.py in run_sync(self, func, timeout)
569 self.stop()
570 timeout_handle = self.add_timeout(self.time() + timeout, timeout_callback)
--> 571 self.start()
572 if timeout is not None:
573 self.remove_timeout(timeout_handle)
/usr/local/lib/python3.6/site-packages/tornado/platform/asyncio.py in start(self)
130 self._setup_logging()
131 asyncio.set_event_loop(self.asyncio_loop)
--> 132 self.asyncio_loop.run_forever()
133 finally:
134 asyncio.set_event_loop(old_loop)
/usr/local/lib/python3.6/asyncio/base_events.py in run_forever(self)
407 self._check_closed()
408 if self.is_running():
--> 409 raise RuntimeError('This event loop is already running')
410 if events._get_running_loop() is not None:
411 raise RuntimeError(
RuntimeError: This event loop is already running
Я пытался:
loop_ = tornado.ioloop.IoLoop.current()
loop_.start(call())
Но это не помогло
async def divide(x, y):
return x / y
async def call():
# This should raise a ZeroDivisionError, but it won't because
# the coroutine is called incorrectly.
await divide(1, 0)
if __name__ == '__main__':
loop_ = tornado.ioloop.IOLoop.current()
loop_.start(call())
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-12-0c16fb86e318> in <module>()
9 if __name__ == '__main__':
10 loop_ = tornado.ioloop.IOLoop.current()
---> 11 loop_.start(call())
TypeError: start() takes 1 positional argument but 2 were given
В общем, я надеваюне знаю, как стратить функцию и получить возвращаемые аргументы