Comments (9)
The fixed has been merged for 3.13, available in 3.13.0-alpha.2, but it still being backported for 3.11 and 3.12.
from chameleon.
Might have to do with some specific expression in your template. Can you try and home in on which expression causes this – assuming that this is the case, that it can be isolated to a particular syntax?
from chameleon.
Unfortunately I'm just not sure where to start with that.
It doesn't happen consistently, so I can't reproduce it locally.
The traceback doesn't seem to point at any specific spot in a template:
Traceback (most recent call last):
--
File "/usr/local/lib/python3.11/site-packages/twisted/internet/defer.py", line 1993, in _inlineCallbacks
result = context.run(
File "/usr/local/lib/python3.11/site-packages/twisted/python/failure.py", line 518, in throwExceptionIntoGenerator
return g.throw(self.type, self.value, self.tb)
File "/usr/src/app/souschef/models/reservation.py", line 438, in email
yield self.request.mailer.send_templated_email(
File "/usr/local/lib/python3.11/site-packages/twisted/python/threadpool.py", line 244, in inContext
result = inContext.theWork() # type: ignore[attr-defined]
File "/usr/local/lib/python3.11/site-packages/twisted/python/threadpool.py", line 260, in <lambda>
inContext.theWork = lambda: context.call( # type: ignore[attr-defined]
File "/usr/local/lib/python3.11/site-packages/twisted/python/context.py", line 117, in callWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "/usr/local/lib/python3.11/site-packages/twisted/python/context.py", line 82, in callWithContext
return func(*args, **kw)
File "/usr/src/app/souschef/utils/mailer.py", line 108, in send_templated_email
_render_html(template, data),
File "/usr/src/app/souschef/utils/mailer.py", line 263, in _render_html
macro = PageTemplate(_load_file('emails/template.pt'))
File "/usr/local/lib/python3.11/site-packages/chameleon/zpt/template.py", line 225, in __init__
super().__init__(body, **config)
File "/usr/local/lib/python3.11/site-packages/chameleon/template.py", line 138, in __init__
self.write(body)
File "/usr/local/lib/python3.11/site-packages/chameleon/template.py", line 241, in write
self.cook(body)
File "/usr/local/lib/python3.11/site-packages/chameleon/template.py", line 168, in cook
program = self._cook(body, digest, names)
File "/usr/local/lib/python3.11/site-packages/chameleon/template.py", line 251, in _cook
source = self._compile(body, builtins)
File "/usr/local/lib/python3.11/site-packages/chameleon/template.py", line 284, in _compile
compiler = Compiler(
File "/usr/local/lib/python3.11/site-packages/chameleon/compiler.py", line 1001, in __init__
module.body += self.visit(node)
File "/usr/local/lib/python3.11/site-packages/chameleon/compiler.py", line 1050, in visit
iterator = visitor(node)
File "/usr/local/lib/python3.11/site-packages/chameleon/compiler.py", line 1094, in visit_Module
program = self.visit(node.program)
File "/usr/local/lib/python3.11/site-packages/chameleon/compiler.py", line 1050, in visit
iterator = visitor(node)
File "/usr/local/lib/python3.11/site-packages/chameleon/compiler.py", line 1113, in visit_MacroProgram
stmts = self.visit(macro)
File "/usr/local/lib/python3.11/site-packages/chameleon/compiler.py", line 1052, in visit
for key, group in itertools.groupby(
File "/usr/local/lib/python3.11/site-packages/chameleon/compiler.py", line 1141, in visit_Macro
body += emit_func_convert_and_escape("__quote")
File "/usr/local/lib/python3.11/site-packages/chameleon/codegen.py", line 68, in wrapper
expr = parse(textwrap.dedent(source), mode=mode)
File "/usr/local/lib/python3.11/site-packages/chameleon/astutil.py", line 45, in parse
return compile(source, '', mode, ast.PyCF_ONLY_AST)
SystemError: AST constructor recursion depth mismatch (before=84, after=119)
Maybe it's a race condition? Should I try wrapping the render function in a mutex?
from chameleon.
Worth noting: I'm seeing tracebacks from all three PageTemplate
calls in the function, so doesn't seem to be specific to any one template.
from chameleon.
If you can share some version of your template, that would be quite helpful – or if that is a problem, you can try and do something akin to a bisection, cutting away half of the template until it compiles. This should help you identify exactly the expression that is causing the problem.
Or you could set up a breakpoint here:
File "/usr/local/lib/python3.11/site-packages/chameleon/codegen.py", line 68, in wrapper
That seems to be the spot where you could find the culprit.
from chameleon.
It doesn't happen consistently. Most of the time, the template will compile successfully, but a handful of times the exact same template will fail to compile.
So far I'm unable to reproduce it locally. And I can't deploy those debugging steps into production.
I wrapped the whole function in a mutex last night and so far no more errors, so it does seem to be a thread safety issue.
from chameleon.
Maybe same issue as #361.
from chameleon.
I tried CHAMELEON_EAGER
as suggested in #361 and that didn't work, but I'm now realizing that's moot if I'm reinstantiating the template every call.
Was able to reproduce locally:
from threading import Thread
from chameleon import PageTemplate
import traceback
import pdb
template = """<html>
<body>
Hello!
</body>
</html>
"""
running = True
def run():
global running
while running:
try:
PageTemplate(template)
except Exception:
if running:
running = False
# pdb.post_mortem()
traceback.print_exc()
t1 = Thread(target=run)
t1.start()
t2 = Thread(target=run)
t2.start()
t1.join()
t2.join()
from chameleon.
This seems to be related to python/cpython#106905 – for now, I think we have to accept that Python 3.11.5 is not compatible with Chameleon.
from chameleon.
Related Issues (20)
- Boolean HTML attribute behavior under >3.8.0 HOT 2
- 4.1.0 wheel doesn't work under Python 3.11 HOT 5
- RFE: is it possible to start making github releases?🤔 HOT 3
- dict-like Scope breaks locals() introspection HOT 2
- 4.3.0 release is breaking on Windows HOT 6
- Fix deprecated ast.Str (replace with ast.Constant)
- Tests are missing in 4.4.1 release HOT 4
- Automated release workflow
- 'PosixPath' object has no attribute 'at' HOT 3
- Type annotations HOT 5
- Find better linting tool HOT 7
- PageTemplateLoader constructor no longer accepts default_extension as a positional argument in v4.5.0 HOT 1
- Static symbols sometimes not correctly imported HOT 1
- 4.5.2: test suite is part of the installed resources and some warnings HOT 5
- Result of use-macro is placed in the wrong position, when using i18n:translate
- How to Have a placeholder preceded immediatly by a $ HOT 3
- Can you put a placeholder inside a placeholder? HOT 4
- I need help with extracting data table from a defaultdict(int) HOT 1
- I get an error message of "Str" HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chameleon.