I'm working on something similar and found that combining GEVENT_MAX_BLOCKING_TIME
with a custom greenlet.settrace()
can help, but the trick is to log only when the block duration exceeds your threshold. You can store the last switch time and compare it inside the trace function to conditionally print the stack trace. Just be sure to set up the trace before starting the hub and apply monkey patching early if you're using it.