Commit b94caeb1 authored by Nane Kratzke's avatar Nane Kratzke
Browse files

parallel space

parent 149d9567
......@@ -5,7 +5,6 @@ import requests
import traceback
import os
import json
from joblib import Parallel, delayed
# A very boring and basic space-service to demonstrate
......@@ -26,10 +25,12 @@ tracer = config.initialize_tracer()
def index():
return redirect('/space')
def load_url(url, key, ctx):
with tracer.start_span(operation_name=key, child_of=ctx) as span:
def load_url(key, url):
return key, json.loads(requests.get(url).content)
#with tracer.start_span(operation_name=key, child_of=ctx) as span:
# return key, json.loads(requests.get(url).content)
def space():
with tracer.start_span(operation_name="space") as parent_span:
......@@ -46,10 +47,10 @@ def space():
"passtime": f"{ lat }&lon={ lon }"
#result = {}
results = Parallel(n_jobs=3)(delayed(load_url)(url, key, parent_span) for key, url in queries.items())
with tracer.start_span(operation_name="parallel", child_of=parent_span) as span:
results = Parallel()(delayed(load_url)(key, url) for key, url in queries.items())
result = { key: content for key, content in results }
#for key, url in queries.items():
# with tracer.start_span(operation_name=key, child_of=parent_span) as span:
# result[key] = json.loads(requests.get(url).content)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment