Debugging+Logging: find out when sync function run in asynq context
LiraNuna opened this issue · comments
As we migrate our code to use asynq, we would love a way to detect usages of sync calls within asynq contexts.
For example, imagine:
@asynq.async()
def data_fetch_1():
return 5
@asynq.async()
def data_fetch_times_2():
data = data_fetch_1()
return data + data
This will incur a sync fetch within an already asynq call which should be fixed since it incurs performance penalties especially when data_fetch_2
is batched.
I have not seen a way to log/debug/add a hook to figure out when this happens
Is Manan's addition in #31 sufficient for your use case?
How can this be turned on?
if you set options.DUMP_SYNC_CALLS
to True in debug.py, you should see a message in stdout every time an async function is called synchronously inside another async function.
I'm guessing like this? If so, this is great, thank you!
from asynq.debug import options
options.DUMP_SYNC_CALLS = True
Yep
We should really document that options mechanism.