I forgot to mention that make_psycopg2_green has to be called
somewhere like at the beginning of init_model call.

And the fun part was that I was able to do something like the
following:

# myproject/lib/app_globals.py
from gevent.event import Event

class Globals(object):
    def __init__(self, config):
        self.messages = []
        self.message_posted = Event()

# myproject/controllers/chat.py

class Chat(BaseController):

    def post(self):
        g.messages.append(request.params['message']
        g.last_modified = timestamp()
        # this is similar to Object.notifyAll() in Java
        g.message_posted.set()
        g.message_posted.clear()

    def watch(self):
        if g.last_modified < request.if_modified_since:
            render('messages', g.messages)
        if not g.message_posted.wait(timeout=I_AM_PRETTY_PATIENT):
            abort(304, 'Not modified')
        response.last_modified = g.last_modified

The biggest thing about above code that I didn't have to worry about
race conditions. Whatever current code does happens in single thread.
No locking needed whatsoever! Isn't that what you were dreaming of in
concurrent programming? Lock-less multi-threading. And there is more -
no GIL overhead :)

I guess this is not suitable for everything but this was another big
thing that made me love Python, Pylons, SQLAlchemy, people who drive
all that and people who love that.

Peace,
Alexander

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to