Skip to content

Replacing Event Loop

Fantix King edited this page Apr 28, 2014 · 3 revisions

This was in a wrong direction. Deprecated now.

loop.run_callback(func, *args)

Replace with loop.call_soon(callback, *args).

In gevent run_callback returns a callback object, while in asyncio call_soon returns a Handle object:

  • Replace callback.stop() with Handle.cancel()
  • Lots of gevent code judges if not my_callback:, but Handle doesn't support it. As a workaround, you can reset the reference to None at the beginning of the callback.

loop.timer(after, repeat=0.0, ref=True, priority=None)

In gevent code this is usually followed by a my_timer.start(callback, *args, update=True). Replace all the two with loop.call_later(delay, callback, *args).

Similarly loop.timer returns a watcher object, while loop.call_later returns a Handle object:

  • Replace my_timer.stop() with Handle.cancel()

loop.io(fd, events, ref=True, priority=None)

Replace with hub.io(fd, flag) which returns a similar IOWatcher object.