Open mselevan opened 8 years ago
I am also seeing this issue if I compile template concurrently. I wonder if this library is not thread safe?
container = self._generate_code(source)
File "/home/dobes/env/lib/python2.7/site-packages/pybars/_compiler.py", line 801, in _generate_code
output = self._compiler(tree).apply('compile')[0]
File "/home/dobes/env/lib/python2.7/site-packages/pymeta/runtime.py", line 299, in apply
val, err = self._apply(r, ruleName, args)
File "/home/dobes/env/lib/python2.7/site-packages/pymeta/runtime.py", line 329, in _apply
[rule(), self.input])
File "/pymeta_generated_code/pymeta_grammar__Grammar.py", line 11, in rule_compile
self.considerError(lastError)
File "/home/dobes/env/lib/python2.7/site-packages/pymeta/runtime.py", line 396, in many
v, _ = fn()
File "/pymeta_generated_code/pymeta_grammar__Grammar.py", line 8, in _G_many_2
_G_exactly_1, lastError = self.exactly('-')
File "/home/dobes/env/lib/python2.7/site-packages/pymeta/runtime.py", line 329, in _apply
[rule(), self.input])
File "/pymeta_generated_code/pymeta_grammar__Grammar.py", line 59, in rule_rule
return (_G_apply_1, self.currentError)
File "/home/dobes/env/lib/python2.7/site-packages/pymeta/runtime.py", line 414, in _or
ret, err = f()
File "/pymeta_generated_code/pymeta_grammar__Grammar.py", line 32, in _G_or_1
_G_exactly_1, lastError = self.exactly('0')
File "/home/dobes/env/lib/python2.7/site-packages/pymeta/runtime.py", line 329, in _apply
[rule(), self.input])
File "/pymeta_generated_code/pymeta_grammar__Grammar.py", line 148, in rule_literal
def _G_or_6():
File "<string>", line 1, in <module>
File "/home/dobes/env/lib/python2.7/site-packages/pybars/_compiler.py", line 589, in add_literal
self._result.grow(u" result.append(%s)\n" % repr(value))
The error seems to be inconsistent ... sometimes it works, and sometimes it doesn't.
@mselevan @dobesv do you have example templates where this happens?
The source code for _compiler.py mentions the compiler is not threadsafe. An alternative way we fixed this without a patch was in our software, we setup lock = threading.Lock(). and then we utilized with lock: for the compiler calls. This blocks other threads from causing issues here. We needed to do this for a project that we have WSGI threads. https://stackoverflow.com/questions/52787026/python-how-to-turn-thread-into-thread-safe
I keep seeing this error during template compilation. Stack trace below