Popular recipes tagged "gevent" but not "pymongo"http://code.activestate.com/recipes/tags/gevent-pymongo/2010-12-08T08:33:30-08:00ActiveState Code RecipesObserver Design Pattern for python gevent coroutine package (Python)
2010-12-08T08:33:30-08:00Andrey Nikishaevhttp://code.activestate.com/recipes/users/4176176/http://code.activestate.com/recipes/577491-observer-design-pattern-for-python-gevent-coroutin/
<p style="color: grey">
Python
recipe 577491
by <a href="/recipes/users/4176176/">Andrey Nikishaev</a>
(<a href="/recipes/tags/event/">event</a>, <a href="/recipes/tags/gevent/">gevent</a>, <a href="/recipes/tags/observer/">observer</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>This is simple implementation of the observer design pattern. Acting as a registration hub, it fires events when requested.
Also i have gevent.Timeout like interface in situations when you need to run event-method in the same greenlet. Example: </p>
<pre class="prettyprint"><code>e = Observer()
ev = e.wait('kill')
try:
gevent.sleep(3)
except FiredEvent:
print 'Fired!'
else:
print 'Not Fired!'
finally:
ev.cancel()
</code></pre>
<p>But rememeber, if you are using subscribe method, event-method will be executed in another greenlet.</p>