Wave apps are servers based on asyncio, Python's library for Asynchronous I/O, and lets you develop and deploy high-performance applications.
@app query handler is invoked every time a user performs some action in your app's UI - access the page, reload it, click a button, access a menu, enter text, and so on. Performing blocking operations in your handler will hang your app's server and make your app's UI appear unresponsive until the blocking operation completes.
In some cases, blocking calls can be pushed to the background to improve concurrency. To achieve this, the Wave API provides two lightweight wrappers over asyncio.run_in_executor():
Here is an example of a function that blocks:
To call the above function from an app, don't do this:
Instead, do this:
q.run() runs the blocking function in the background, in-process.
Depending on your use case, you might want to use a separate process pool or thread pool from Python's multiprocessing library, like this:
q.exec() accepts a custom process pool or thread pool to run the blocking function.