Skip to content

Can't run bta-lib inside a thread #9

Open
@karaolidis

Description

Hello, I'm trying to use btalib and I'm having some trouble when having it run from inside a thread.

The below code works fine:

import [...]

symbol = 'BTCEUR'

with open('./data/' + symbol + '/' + symbol + '_kline.p', 'rb') as handle:
    kline_df = pickle.load(handle)

sma = btalib.sma(kline_df).df
print(sma)

But when I try to use threads...

import [...]

symbol = 'BTCEUR'

with open('./data/' + symbol + '/' + symbol + '_kline.p', 'rb') as handle:
    kline_df = pickle.load(handle)

def thread():
    sma = btalib.sma(kline_df).df
    print(sma)
    time.sleep(5)

x = threading.Thread(target=thread)
x.start()

... I get the following error:

Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.9/threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "/home/nick/storage/Documents/_Projects/Python/Crypto/btalib_test.py", line 13, in thread
    sma = btalib.sma(kline_df).df
  File "/home/nick/storage/Documents/_Projects/Python/Crypto/venv/lib/python3.9/site-packages/btalib/indicator.py", line 110, in __call__
    self.outputs = self.o = meta.outputs._from_class(cls)
  File "/home/nick/storage/Documents/_Projects/Python/Crypto/venv/lib/python3.9/site-packages/btalib/meta/outputs.py", line 30, in _from_class
    return _CLSOUTPUTS[cls]()  # defvals params in dict format
  File "/home/nick/storage/Documents/_Projects/Python/Crypto/venv/lib/python3.9/site-packages/btalib/meta/lines.py", line 630, in __init__
    metadata.minperiods[self] = [1] * len(self)
AttributeError: '_thread._local' object has no attribute 'minperiods'

Any help would be appreciated!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions