Created
March 28, 2012 12:07
-
-
Save alfetopito/2225687 to your computer and use it in GitHub Desktop.
Celery eventlet tryout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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