Question

Did someone measure in Python the speed and usefulness of pyev over standard binding through select from Python stdlib?

What are benefits of using pyev over select?

pyev is build by C extension, so it is not portable solution. I try to build it with PyPy and out of the box didn't succeed.
So I'm just wondering if it's worth to use it.

I know that gevent uses libev in it's 1.0 version (and before they used libevent). Do they really need it? I don't care about non event loop functionality (like dns from libevent).

Was it helpful?

Solution

Python's select module is just a wrapper around select(), poll() and epoll() syscalls, whereas libev and libevent implement an event loop. An event loop manages watchers and timers, queues pending events, calls your callbacks etc.

If you want to compare libev/libevent to Python counterparts, you'd need to compare them to twisted's reactor and tornado's IOLoop.

From libev documentation:

Here are the gory details of what ev_run does (this is for your understanding, not a guarantee that things will work exactly like this in future versions):

   - Increment loop depth.
   - Reset the ev_break status.
   - Before the first iteration, call any pending watchers.
   LOOP:
   - If EVFLAG_FORKCHECK was used, check for a fork.
   - If a fork was detected (by any means), queue and call all fork watchers.
   - Queue and call all prepare watchers.
   - If ev_break was called, goto FINISH.
   - If we have been forked, detach and recreate the kernel state
     as to not disturb the other process.
   - Update the kernel state with all outstanding changes.
   - Update the "event loop time" (ev_now ()).
   - Calculate for how long to sleep or block, if at all
     (active idle watchers, EVRUN_NOWAIT or not having
     any active watchers at all will result in not sleeping).
   - Sleep if the I/O and timer collect interval say so.
   - Increment loop iteration counter.
   - Block the process, waiting for any events.
   - Queue all outstanding I/O (fd) events.
   - Update the "event loop time" (ev_now ()), and do time jump adjustments.
   - Queue all expired timers.
   - Queue all expired periodics.
   - Queue all idle watchers with priority higher than that of pending events.
   - Queue all check watchers.
   - Call all queued watchers in reverse order (i.e. check watchers first).
     Signals and child watchers are implemented as I/O watchers, and will
     be handled here by queueing them when their watcher gets executed.
   - If ev_break has been called, or EVRUN_ONCE or EVRUN_NOWAIT
     were used, or there are no active watchers, goto FINISH, otherwise
     continue with step LOOP.
   FINISH:
   - Reset the ev_break status iff it was EVBREAK_ONE.
   - Decrement the loop depth.
   - Return.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top