refactor gevent.Event sync into a context manager