Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Remove use of threads when retrieving layers #846

Merged
merged 1 commit into from
Dec 22, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 4 additions & 21 deletions regulations/generator/generator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import re
from threading import Thread

from django.conf import settings

Expand Down Expand Up @@ -88,33 +87,17 @@ def add_layer(self, layer_name, regulation, version, sectional=False):
self.appliers[applier_type].add_layer(layer)

def add_layers(self, layer_names, regulation, version, sectional=False):
"""Request a list of layers. As this might spawn multiple HTTP
requests, we wrap the requests in threads so they can proceed
concurrently."""
"""Request a list of layers."""
#This doesn't deal with sectional interpretations yet.
#we'll have to do that.
layer_names = set(filter(lambda l: l.lower() in LayerCreator.LAYERS,
layer_names))
results = []
procs = []

def one_layer(layer_name):
api_name, applier_type,\
layer_class = LayerCreator.LAYERS[layer_name]
layer_json = self.get_layer_json(api_name, regulation, version)
results.append((api_name, applier_type, layer_class, layer_json))

# Spawn threads
for layer_name in layer_names:
proc = Thread(target=one_layer, args=(layer_name,))
procs.append(proc)
proc.start()

# Join them (once their work is done)
for proc in procs:
proc.join()

for api_name, applier_type, layer_class, layer_json in results:
api_name, applier_type, layer_class = LayerCreator.LAYERS[layer_name]
layer_json = self.get_layer_json(api_name, regulation, version)

if layer_json is None:
logging.warning("No data for %s/%s/%s"
% (api_name, regulation, version))
Expand Down