Skip to content

Commit 7f5c257

Browse files
committed
Refactoring on worker threads.
1 parent fab788f commit 7f5c257

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

app/app.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,43 +38,41 @@ def main():
3838
logger.info("No configured markets, using all available on exchange.")
3939
market_data = exchange_interface.get_exchange_markets()
4040

41-
# notifier = Notifier(config.notifiers, market_data)
42-
4341
thread_list = []
4442

4543
for exchange in market_data:
46-
num = 1
47-
for chunk in split_market_data(market_data[exchange]):
44+
for key in market_data[exchange].keys():
45+
4846
market_data_chunk = dict()
49-
market_data_chunk[exchange] = { key: market_data[exchange][key] for key in chunk }
47+
market_data_chunk[exchange] = {key : market_data[exchange][key]}
5048

51-
notifier = Notifier(config.notifiers, config.indicators, market_data_chunk)
52-
behaviour = Behaviour(config, exchange_interface, notifier)
49+
workerName = "Worker-{}-{}".format(exchange, key)
5350

54-
workerName = "Worker-{}".format(num)
51+
notifier = Notifier(config.notifiers, config.indicators, market_data_chunk)
52+
behaviour = Behaviour(config, exchange_interface, notifier)
53+
5554
worker = AnalysisWorker(workerName, behaviour, notifier, market_data_chunk, settings, logger)
5655
thread_list.append(worker)
5756
worker.daemon = True
5857
worker.start()
59-
60-
time.sleep(60)
61-
num += 1
62-
58+
time.sleep(2)
59+
6360
logger.info('All workers are running!')
6461

6562
for worker in thread_list:
6663
worker.join()
6764

65+
"""
6866
def split_market_data(market_data):
6967
if len(market_data.keys()) > 20:
7068
return list(chunks(list(market_data.keys()), 20))
7169
else:
7270
return [list(market_data.keys())]
7371
7472
def chunks(l, n):
75-
"""Yield successive n-sized chunks from l."""
7673
for i in range(0, len(l), n):
7774
yield l[i:i + n]
75+
"""
7876

7977
class AnalysisWorker(Thread):
8078

0 commit comments

Comments
 (0)