Search code examples
pythonmultithreadingpython-2.7python-3.xeventlet

Block execution until condition


I am using eventlet and have two main process running. One of the process acts as a producer and the other as consumer. The problem is that instead of using queue from eventlet package I want to use a db. Using queue I can simple pass (block=True) as argument and eventlet would take care of bloking execution of the consumer routine untill the producer puts something in queue. If I replace queue with db how do I efficiently implement blocking logic.


Solution

  • Look for data in DB every N seconds. If nothing found - sleep.

    UPDATE: or use Postgresql LISTEN/NOTIFY mechanism as shown in http://initd.org/psycopg/articles/2010/12/01/postgresql-notifications-psycopg2-eventlet/