You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug: Tasks created by Page.run_task can not be awaited #6515
I have searched the opened issues and there are no duplicates
Describe the bug
The Page.create_task returns a Future object of concurrent.futures.Future type. This type of Future object is not awaitble.
As awaiting is often essential with asynchronous applications, it would be nice if the run_task could return an awaitable type, such as asyncio.Future or asyncio.Task.
It is possible to use Page.loop.create_future() or Page.loop.create_task() to get awaitable Task or Future objects, but somehow those do not seem to integrate with Flet event loop as well as Page.create_task, as sometimes the UI does not update as expected.
It seems this is expected behavior with the current page.run_task() implementation, rather than a bug in await itself.
page.run_task() is primarily designed to submit a coroutine to the page's event loop as a background task—especially from synchronous callbacks or lifecycle hooks. Internally, it uses asyncio.run_coroutine_threadsafe(...) , which returns a concurrent.futures.Future by design. As a result, the returned object is not directly awaitable.
Therefore, run_task() should be treated as a scheduling API, not as the async equivalent of asyncio.create_task().
In native async code, the preferred patterns are: await coro() await page.loop.create_task(coro())
If you just want to run a task without waiting for it, you can simply call page.run_task(). However, if you do need to await the result, you must wrap the future as shown below:
import flet as ft
import asyncio
async def main(page: ft.Page):
async def coro():
print("running coroutine")
# Get the concurrent.futures.Future returned by page.run_task
concurrent_future = page.run_task(coro)
# Wrap it into an asyncio.Future using asyncio.wrap_future, then await it
asyncio_future = asyncio.wrap_future(concurrent_future)
await asyncio_future
print("awaited successfully\n")
ft.run(main)
Activity
ihmily commentedon May 25, 2026
It seems this is expected behavior with the current
page.run_task()implementation, rather than a bug in await itself.page.run_task()is primarily designed to submit a coroutine to the page's event loop as a background task—especially from synchronous callbacks or lifecycle hooks. Internally, it usesasyncio.run_coroutine_threadsafe(...), which returns aconcurrent.futures.Futureby design. As a result, the returned object is not directly awaitable.Therefore,
run_task()should be treated as a scheduling API, not as the async equivalent ofasyncio.create_task().In native async code, the preferred patterns are:
await coro()await page.loop.create_task(coro())If you just want to run a task without waiting for it, you can simply call
page.run_task(). However, if you do need to await the result, you must wrap the future as shown below: