Created
November 27, 2022 15:19
-
-
Save hclivess/ce35b73e4e536b61aaec67090e23967d to your computer and use it in GitHub Desktop.
minimalistic asyncio on synchronous functions that do not support it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
def static_hi(this): | |
"""this function is not asynchronous""" | |
return this | |
async def printer(): | |
"""notice arguments are not passed directly""" | |
return await asyncio.to_thread(static_hi, this="haha") | |
async def main() -> None: | |
r = await asyncio.gather(printer()) | |
print(r) | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment