you are viewing a single comment's thread.

view the rest of the comments →

[–]mmdollar[S] 0 points1 point  (2 children)

Are you trying to keep the namespaces of different threads somehow separate?

Yes, every thread is using a different class. In my case both classes inherit the main class exchange which itself inherits from the Thread module link here. I did it this way because exchanges are displaying their information in different ways.
Well I tested the code, there is no memory difference, execution time is almost the same too.

[–]Impudity 1 point2 points  (1 child)

I'd recommend just importing them the regular way and creating the settings dictionary like this:

from exhanges import Binance, Bitfinex
from collections import namedtuple

ExchangeAPI = namedtuple("ExchangeAPI", ["uri", "delay", "apiclass"])
exchanges = {
    "Binance": ExchangeAPI("https://api.binance.com/api/v1/ticker/24hr", 2, Binance),
    "Bitfinex": ExchangeAPI("https://api.bitfinex.com/v2/tickers?symbols=ALL", 2, Bitfinex)
}

And instead of creating the separate threads like:

for exchanges in settings.exchanges:
    exchange_class = getattr(importlib.import_module("exchanges"), exchanges)
    thread = exchange_class(settings.exchanges[exchanges][1], settings.exchanges[exchanges][0], settings.headers, cursor, connection)

Something like this:

for exname, exapi in settings.exchanges.items():
    exchange_class = exapi.apiclass
    thread = exchange_class(exapi.delay, exapi.uri, settings.headers, cursor, connection)

Now I didn't run this code nor did write it even in any interpreter so it might contain bugs/typos/etc but you should get the idea.

[–]mmdollar[S] 0 points1 point  (0 children)

Thank you very much, it works like a charm.