Is it possible to log info anytime gevent switches from one greenlet to another?
Why I want to do this...
I'm investigating an issue where it appears that greenlets aren't getting swapped in quickly enough. I see situations where a greenlet makes an async call and therefore yields, but it doesn't get to run again for a long time (1-2 minutes), long past the point where (I believe) the resource it was waiting for is available.
Worth noting that the CPU usage is pegged at 100%, so the problem may very well be a lack of actual resources, but I'd like to make sure. If could print a greenlet ID + timestamp whenever a greenlet is swapped in or out, I could verify whether this is what's happening.
I started looking at the source code, adding my own print statements using id(getcurrent()) in various switch/switch_out functions, but so far I haven't found the right approach, so I would appreciate some guidance.
Related - does gevent schedule greenlets in FIFO order? In other words, does gevent look at all greenlets that are not blocked and pick the one that started waiting longest ago to run next?
thanks,
--S