-
|
Static checkers and IDEs assume that any module is run in sync mode and treat I couldn't find any universal pragma or something in Python marking "this module would be run in async mode". For now I resolved it with from asyncio import create_task
async def main() -> None:
...
if __name__ == '__main__':
create_task(main())But maybe it's actually bad for PyScript, I don't know. Is Is there any other solution for this, except silencing every tool used explicitly? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
|
I am assuming that code is supposed to run on both Python and PyScript ... accordingly, be aware that MicroPython might not like that or not be fully compatible with |
Beta Was this translation helpful? Give feedback.
Summarizing my experience with Pyodide reply at pyodide/pyodide#6065:
–
asyncio.run()is NOT working (now) on Firefox and Safari because they don't support JSPI (yet).–
asyncio.create_task()is working in Chrome/Firefox/Safari, so can be used.– However the best solution (for now) is to just call
await, and mark the line to be ignored by static checkers.– If the module is supposed to be used in both sync and async contexts, it should use branching and behave differently in different contexts, like using an existing event loop or starting a new one.
– CPython allows top-level await by setting
PyCF_ALLOW_TOP_LEVEL_AWAIT, but there is no way to detect that setting statically by checkers.–…