Skip to content

Instantly share code, notes, and snippets.

@hclivess
Created November 27, 2022 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hclivess/ce35b73e4e536b61aaec67090e23967d to your computer and use it in GitHub Desktop.
Save hclivess/ce35b73e4e536b61aaec67090e23967d to your computer and use it in GitHub Desktop.
minimalistic asyncio on synchronous functions that do not support it
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