Skip to content

Instantly share code, notes, and snippets.

@alfetopito
Created April 2, 2012 19:30
Show Gist options
  • Save alfetopito/2286575 to your computer and use it in GitHub Desktop.
Save alfetopito/2286575 to your computer and use it in GitHub Desktop.
Celery eventlet tryout 2
import eventlet
import tasks
json = eventlet.import_patched('json')
from eventlet.queue import LightQueue
from time import sleep
eventlet.monkey_patch()
def processTask(cfgFile):
print ("Processing stuff here")
result = tasks.doStuff(cfgFile)
result.wait()
print ("Processing stuff more here")
class Base(object):
"""
Should be the base for launching tasks
"""
poll = eventlet.GreenPool()
queue = LightQueue()
def __init__(self):
self._running = None
def queueTask(self, item):
print ("Queueing " + item)
self.queue.put(item)
if self._running == None:
self._running = self.poll.spawn(self.run)
def run(self):
q = self.queue
try:
while True:
try:
item = q.get(block=False, timeout=1)
print ("Dequeued " + item)
self.poll.spawn_n(processTask, item)
except eventlet.queue.Empty:
sleep(1)
except KeyboardInterrupt:
print ("Keyboard interrupt, exiting...")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment