Skip to content

Instantly share code, notes, and snippets.

@wolever
Created May 28, 2012 18:24
Show Gist options
  • Save wolever/2820445 to your computer and use it in GitHub Desktop.
Save wolever/2820445 to your computer and use it in GitHub Desktop.
Some issues we've encountered with gevent

Below are some issues we encountered during our first real deployment of gevent. It is being used on one host to communicate over ethernet (ie, using raw ethernet packets) with approximately 700 PIC32 microprocessors, and it is used for communication between all of the services we have built (approximately 15 unique services running on two hosts).

  • The majority of the issues we faced were caused by a particular service which communicates with a child process over stdin/stdout. Not all of the issues were gevent specific (for example, when the child wasn't properly selecting on stdout, the kernel was silently dropping data when its internal buffer filled up, even though fwrite reported that the data had been written).

  • We are using gevent-0.13.7 with libevent-2.0.x. I would like to be using gevent-1.0, but it was causing some issues (I don't recall exactly what they were) on OS X, so we rolled back to 0.13.7.

  • libevent-1.4.13-stable (packages with Debian stable 6.0.4) would, under moderate load, block indefinitely on calls to wait_write (manually creating an EV_WRITE event had similar issues). I wasn't able to fully diagnose this issue, as my co-worker was able to upgrade to libevent-2.0.19-stable which made the issue go away.

  • It's not obvious how to perform non-blocking I/O on generic file descriptors. There isn't an obvious non-blocking version of os.read/os.write. After some searching, the trick is to manually use fcntl to set O_NONBLOCK, then use wait_read and wait_write. From the process.py example:

    ```python
    fcntl.fcntl(stdin, fcntl.F_SETFL, os.O_NONBLOCK)
    wait_read(stdin.fileno())
    data = os.read(stdin.fileno(), 4096)
    ```
    
  • Note that gevent-1.x will inclue gevent.subprocess, which will make subprocess fiddling simpler.

  • There have been a copule of instances where it would have been nice to use kernel threads, but this hasn't been a huge issue, and gevent-1.x will allow kernel threads.

Please note: this is in no way a criticism of gevent. We (the two developers) are very happy with our decision to depend so heavily on gevent: it has simplified many aspects of development (just to name a few things that come immediately to mind): we simply don't have intra-process concurrency-related bugs, the deterministic nature of cooperative multithreading makes debugging and testing easy, and the Timeout context manager is great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment