Skip to content

Instantly share code, notes, and snippets.

@alfetopito
Created March 28, 2012 12:07
Show Gist options
  • Save alfetopito/2225687 to your computer and use it in GitHub Desktop.
Save alfetopito/2225687 to your computer and use it in GitHub Desktop.
Celery eventlet tryout
import eventlet
import tasks
#from json import dump, load
from django.conf import settings
from glob import glob
json = eventlet.import_patched('json')
eventlet.monkey_patch()
poll = eventlet.GreenPool()
def processTask(cfgFile):
cfg_str = json.load(open(cfgFile, "r"))
result = tasks.scrape.apply_async(kwargs={'cfg_str':cfg_str})
result.wait()
output = result.result
outFile = open('output.json', "w")
json.dump(output, outFile)
outFile.close()
print ("finished {0}".format(result.task_id))
def lauchTasks():
for cfg_file in glob('*.json'):
print(cfg_file)
print poll.spawn(processTask, cfg_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment