Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize the thread local in parser module in every thread #267

Merged
merged 2 commits into from
May 14, 2024
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
17 changes: 9 additions & 8 deletions thriftpy2/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,6 @@ def set_info(self, info):
return self.index + 1


threadlocal.incomplete_type = CurrentIncompleteType()


def p_ref_type(p):
'''ref_type : IDENTIFIER'''
ref_type = threadlocal.thrift_stack[-1]
Expand Down Expand Up @@ -515,11 +512,6 @@ def p_type_annotation(p):
p[0] = p[1], None # Without Value


threadlocal.thrift_stack = []
threadlocal.include_dirs_ = ['.']
threadlocal.thrift_cache = {}


def parse(path, module_name=None, include_dirs=None, include_dir=None,
lexer=None, parser=None, enable_cache=True, encoding='utf-8'):
"""Parse a single thrift file to module object, e.g.::
Expand All @@ -543,6 +535,15 @@ def parse(path, module_name=None, include_dirs=None, include_dir=None,
cached, this is enabled by default. If `module_name`
is provided, use it as cache key, else use the `path`.
"""
# threadlocal should be initialized in every threads
initialized = getattr(threadlocal, 'initialized', None)
if initialized is None:
threadlocal.thrift_stack = []
threadlocal.include_dirs_ = ['.']
threadlocal.thrift_cache = {}
threadlocal.incomplete_type = CurrentIncompleteType()
threadlocal.initialized = True

# dead include checking on current stack
for thrift in threadlocal.thrift_stack:
if thrift.__thrift_file__ is not None and \
Expand Down
Loading