Skip to content

Instantly share code, notes, and snippets.

@noonat
Created September 26, 2014 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noonat/2bdf39d5950d91b4ad44 to your computer and use it in GitHub Desktop.
Save noonat/2bdf39d5950d91b4ad44 to your computer and use it in GitHub Desktop.
import gevent
import greenlet
import logging
import time
import traceback
_last_switch_time = None
_min_elapsed_time = 0.1
def trace(event, (origin, target)):
global _last_switch_time
last_switch_time = _last_switch_time
current_time = _last_switch_time = time.time()
if last_switch_time is not None:
elapsed_time = current_time - last_switch_time
if elapsed_time < _min_elapsed_time:
return
if origin is gevent.hub.get_hub():
return
logging.error('greenlet blocked event loop for %.4f seconds: %s',
elapsed_time, traceback.format_stack())
greenlet.settrace(trace)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment