Questions About Gevent

How make a python windows service of a flask/gevent.socketio server?

I have a flask/gevent SocketIOServer and need to make it work as a service:

class TeleportService(win32serviceutil.ServiceFramework):
    _svc_name_ = "TeleportServer"
    _svc_display_name_ = "Teleport Database Backup Service"
    _svc_description_ = "More info at"

    def __init__(self, args):
        win32serviceutil.ServiceFramework.__init__(self, args)
        self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)

    def SvcStop(self):

    def SvcDoRun(self):
                              servicemanager.PYS_SERVICE_STARTED, (self._svc_name_, ''))



def runServer():
    print 'Listening on %s...' % WEB_PORT
    ws = SocketIOSe

gevent block redis' socket request

GOAL:spawn a few greenlet worker deal with the data pop from redis (pop from redis and then put into queue)

RUNNING ENV: ubuntu 12.04 PYTHON VER: 2.7 GEVENT VER: 1.0 RC2 REDIS VER:2.6.5 REDIS-PY VER:2.7.1

from gevent import monkey; monkey.patch_all()
import gevent
from gevent.pool import Group
from gevent.queue import JoinableQueue
import redis

tasks = JoinableQueue()
task_group = Group()

def crawler():
    while True:
        if not tasks.empty():
            print tasks.get()

redis_client = redis.Redis()
data = redis_client.lpop('test') #<----------Block here

Try to pop data from redis, but it blocked..and no exception raised...just freeze and remove spawn method ,it will worked.. i feel confuse what happened, plz help! thk u!

How to get POST variables in Python, when using gevent?

This is the question:How to get POST variables in Python, when using gevent?

The following is passed to the application:

def application(env, start_response):

And this is the other part:

if __name__ == '__main__':
print 'Serving on 8080...'
WSGIServer(('', 8080), application).serve_forever()

But env doesn't contain my POST!

Please enlighten me - where does my misunderstanding lie?

Thank you!

What does make significant difference of performance between eventlet and gevent?

Those two libraries share the similar philosophy and the similar design decisions as a result. But this popular WSGI benchmark says eventlet is way slower than gevent. What do make their performance so different?

As I know key differences between them are:

Differences between gevent and tornado

I understand that both tornado and gevent are asynchronous python frameworks.

While reading the bottle documentation I found that gevent actually is NOT asynchronous, and you can create thousands to pseudo-threads that work synchronously.

Seondly, in gevent, you can not terminate the request handler early and you need to return the full response, while in tornado you can. (correct me if I'm wrong here)

Can some one describe in detail how these systems work internally, and in what ways they are different. Also, how does WSGI play with the asynchronous nature of these systems? Do these frameworks conform to WSGI, if yes, how?

gevent 'with Timeout' stopped working

I have upgraded from gevent 13.x to 1.0b4.

I have Failover code that checks if a connection is till alive by sending "HUGZ" every 5 seconds. If HUGZ's fail to arrive a an alternative connection to a different location is made. This failover mechanism stopped working because Timeout behaviour changed.

I made some test code with a with Timeout and the and it works as expected, BUT the exact same code does not work anymore in my the context of my application. The failover code used to work before.

I'm using gevent-zeromq to recv messages in a with TimeOut block, but the with TimeOut blocks, and never 'times outs` and continues execution, so recovery code is not getting executed.

What could cause the Timeout mechanism not to be working? The previously working Timeout code does not work anymore.

if active_socket:
    print 'waiting for message'

    with Timeout(2, False):
        node_message = NodeM

Attempting to use gevent library in Python: "ImportError: cannot import name core"

I'm attempting to use the gevent library in a Python app I'm writing. However, both easy_install and installing it manually appears to be failing. Any suggestions?

Python 2.6.2 (r262:71600, Aug  5 2009, 10:31:21) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gevent
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "gevent/", line 28, in <module>
    from gevent.greenlet import Greenlet, joinall, killall
  File "gevent/", line 5, in <module>
    from gevent import core
ImportError: cannot import name core

The complete dump of my "build" and "install" commands are:

(env)[root@test1:downloads/gevent-0.10.0]# python build                                        (02-20 16:00)
found syst

Google Maps add 2 GEvent Listeners. 1 for each marker

I have the following code which lets the user plot two points on a Google MAP. I then want to be able to catch the event for each point(marker) being dragged to a new location. I am bad at Javascript and have spent hours trying to do this so I think it's time I get some help..

What I am trying to do is get the user to plot two points(markers) draggable on the map. I then want to be able to have my script write the positions(lat,long) to the document. I will then calculate the distance between these as part of a shipping app I am making.

I would like to have the contents of the document (lat,long) updated when a marker(point) is dragged to a new location.

Also, I fixed a schoolboy error where the point vars were being decalred inside the switch statement. My problem is fixed by moving the Add event listener statements inside the switch statement. Thanks Cannonade :)

The next thing now is to try and calculate the distance (crow flies) between the two po

gevent install on x86_64 fails: "undefined symbol: evhttp_accept_socket"

I'm trying to install gevent on a fresh EC2 CentOS 5.3 64-bit system.

Since the libevent version available in yum was too old for another package (beanstalkd) I compiled/installed libevent-1.4.13-stable manually using the following command:

./configure --prefix=/usr && make && make install

This is the output from installing gevent:

[gevent-0.12.2]# python build --libevent /usr/lib
Using libevent 1.4.13-stable:
running build
running build_py
running build_ext
Linking /usr/src/gevent-0.12.2/build/lib.linux-x86_64-2.6/gevent/ to 
[gevent-0.12.2]# cd /path/to/my/project
[project]# python
Traceback (most recent call last):
  File "", line 9, in <module>
    from gevent.wsgi import WSGIServer as GeventServer
  File "/usr/lib/python2.6/sit

GEvent.addListener(...) return?

my Question is as follows: What does GEvent.addListener(map, "click" function(){...}) return into the callback function? I don't find any information in the GMaps reference at all, can you show me some? The only thing I found out was that there are two parameters, "overlay" and "latLng" that are passed. The name of these parameters should not be of interest right? I could also name them "foo" and "bar" as far as I know. But the parameter "overlay" seems to be empty anyway?

Also I have problems passing these two parameters directly into a callback function I created myself which looks like that...

    GEvent.addListener(gmap, "click", generateMarker(overlay, latLng));

... instead of writing the following, which actually works fine.

    GEvent.addListener(gmap, "click", function(overlay, latLng) {
        generateMarker(overlay, latLng);

context switching with 'yield'

I was reading a gevent tutorial and saw this interesting snippet:

import gevent

def foo():
    print('Running in foo')
    print('Explicit context switch to foo again')

def bar():
    print('Explicit context to bar')
    print('Implicit context switch back to bar')


In which the flow of execution goes like this foo -> bar -> foo -> bar . Is it not possible to do the same without the gevent module but with yield statements? I've been trying to do this with 'yield' but for some reason I can't get it to work... :(

Synchronous reading of a multipart upload alongside Django

I have a Django application which needs to have access to reading multipart file uploads as file-like objects as they're uploaded, which means that I need more or less synchronous access to the request object and a way to unpack it in chunks to binary data. Django unfortunately handles uploads by moving them directly into memory or to temporary files, which won't work for my use case.

Some one recommended that I use gevent/greenlet to handle the upload, but I'm not sure how that plays into the equation and what setup is required alongside Django to make it work. Plus, running something outside of Django would mean that I would have to implement a database connection layer to validate that the upload is allowed (using a ticket id).

With this said, how can I set this up? Django should be running in a WSGI application, and someone had also recommended writing a second WSGI application to capture a single URL path for uploads. I'd like to essentially take as

Multiple Polylines - need to change the color

I am new to Google Maps - I am trying to change the color of the second polyline on my map.

Here is what I have so far ~

var direction = new GDirections(); 

direction.load("from: Oregon 99, near, Halsey, Oregon to: Oregon 34, near, Tangent, Oregon to: Interstate 5, near, Tigard, Oregon to: Oregon 217, near, Cedar Hills, Oregon to: U.S. 26, near, North Plains, Oregon to: U.S. 26, near, Tigard, Oregon to: Interstate 405, near, Portland, Oregon to: Interstate 5, near, Vancouver, Wa to: Interstate 5, near, Carrolls, Wa to: Washington 432,  near, Longview, Wa to: Washington 433, near, Rainier, Oregon to: U.S. 30, Wauna, Oregon", {getPolyline:true});

                   function(){ map.addOverlay(direction.getPolyline()); }

Can someone help me change this polyline to any other color.

Thanks an advance!


kill pserve(Gunicorn) specific server from pyramid

i use pyramid with pserve running Gunicorn like this:

pserve production.ini


use = egg:gunicorn#main
host =
port = 8080
workers = 3
worker_class = gevent
daemon = true

and it returns the PID

Starting server in PID XXXXX.

but i can't kill it by running

# kill XXXXX
-bash: kill: (XXXXX) - No such process


# pserver --stop-daemon XXXXX
No PID File exists in

till now, i've been using

pkill pserve

but now, i have multiple servers running, so it will kill all my servers.

how can i kill a specific running server?

Dealing with upgrade of libevent on Amazon AWS

I am building an application (in Python) on Amazon EC2 that has a following dependency chain:

gevent-websocket ---> gevent ---> libevent

The last one (libevent) got upgraded on Sunday and my server is now generating this error:

  File "/usr/lib/python2.6/site-packages/gevent-0.13.7-py2.6-linux-x86_64.egg/gevent/", line 41, in <module>
    from gevent import core
ImportError: cannot open shared object file: No such file or directory

Not wanting to spend much time on the issue, I tried to mitigate it by creating a symlink to an always-recent version:

$ sudo ln -s /usr/lib64/ /usr/lib64/

But it d

In supervisord umask setting results in same permissions for files and folders

I'm using supervisord to handle some gevent based wsgi processes that simply run a django app.

When I upload files I want them to have rw permissions for user and group (www-data) and of course I want the folders to have execute permissions for user and group as well.

Normally a umask would subtrack from 777 for folders but 666 for files, however I find that setting the umask in a supervisor config results in the same permissions for files and folders, so when I set umask to 002, all the files uploaded get execute permissions. I also tried setting the umask to 113 but then I can't execute any folders.

I'm not 100% sure this is supervisors fault and not gevent or django related. Any ideas?

Clarification: Does Heroku Run Python Apps Behind Nginx or Not?

TL/DR: My primary question: Is it worth my time to try to add NGinx to my Django/Gunicorn/Cedar/PostgresSql app or does Heroku do this type of performance improvement for me?

In the Cedar documentation (, it clearly states that cedar does not support a reverse-proxy. "Cedar does not include a reverse proxy cache such as Varnish, preferring to empower developers to choose the CDN solution that best serves their needs."

Again in the Routing article (, it is specified that nginx is not done automatically: 'Since requests to Cedar apps are made directly to the application server ??? not proxied through an HTTP server like nginx ??? any compression of responses must be done within your application."

However, in the Python Faq, it says otherwise:

Django: Cleaning up redis connection after client disconnects from stream

I've implemented a Server Sent Event API in my Django app to stream realtime updates from my backend to the browser. The backend is a Redis pubsub. My Django view looks like this:

def event_stream(request):
   Stream worker events out to browser.

   listener = events.Listener(

   return http.HttpResponse(listener, mimetype='text/event-stream')

And the events.Listener class that I'm returning as an iterator looks like this:

class Listener(object):
    def __init__(self, rcon_or_url, channels, buffer_key=None,
        if isinstance(rcon_or_url, redis.StrictRedis):
            self.rcon = rcon_or_url