I have an asynchronous route in Quart in which I have to run a block of code that is synchronous. According to the documentation I should use run_sync from quart.utils to ensure that synchronous function does not block the event loop.
def sync_processor():
request = requests.get('https://api.github.com/events')
return request
@app.route('/')
async def test():
result = run_sync(sync_processor)
print(result)
return "test"
However the print(result) returns <function sync_processor at 0x742d18a0>. How can I get the request object instead of the <function sync_processor at 0x742d18a0>.
You are missing an
await
asrun_sync
wraps the function with a coroutine function that you then need to call, i.e.result = await run_sync(sync_processor)()
or in full,