Open this example in the interactive library
Source code
import asyncio
async def main():
return await asyncio.to_thread(sum, [1, 2, 3])
print(asyncio.run(main()))Sample output
6

Run blocking work in a thread. A self-contained example using the Python standard library.
Open this example in the interactive library
import asyncio
async def main():
return await asyncio.to_thread(sum, [1, 2, 3])
print(asyncio.run(main()))6