Skip to content

Commit

Permalink
Changed as per Initialize thread local value on each thread mementum#4
Browse files Browse the repository at this point in the history
…in btalib parent.
  • Loading branch information
neilsmurphy committed Aug 24, 2021
1 parent b4bdc32 commit 4d02b93
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion btalib/indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
]


metadata.callstack = [] # keep indicators which are currently being executed
metadata.register('callstack', list) # keep indicators which are currently being executed


_NAMES_IND = {}
Expand Down
4 changes: 2 additions & 2 deletions btalib/meta/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,8 @@ def _applymulti(self, func, *args, raw=False, **kwargs):
# instances, to avoid having them declared as attributes. Or else __setattr__
# would set them as Line objects (or logic would be needed in __setattr__ to
# avoid assigning an object not the real value
metadata.minperiods = {}
metadata.minperiod = {}
metadata.register('minperiods', dict)
metadata.register('minperiod', dict)


class Lines:
Expand Down
18 changes: 17 additions & 1 deletion btalib/meta/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,20 @@

__all__ = ['metadata']

metadata = threading.local()
class Metadata(object):

def __init__(self):
self._metadata = threading.local()

@classmethod
def register(cls, name, default=None):

def get_or_default(self):
if not hasattr(self._metadata, name):
setattr(self._metadata, name, default())
return getattr(self._metadata, name)

setattr(cls, name, property(get_or_default))


metadata = Metadata()

0 comments on commit 4d02b93

Please sign in to comment.