I recently migrated a Django web app from one PythonAnywhere instance to another (same codebase, new environment).
Expected Behaviour
Django should log warnings/error normally without affecting request handling
Actual Behaviour
On the new instance, any Django warning triggers a logging loop that results in:
RecursionError: maximum recursion depth exceeded while calling a Python object
From the traceback, the recursion appears to follow this pattern:
logging → stream.write → logger.error → logging → ...
Specifically, it looks like logging is writing to a stream wrapped by:
/bin/user_wsgi_wrapper
whose write() method calls logger.error(), causing infinite recursion.
This behaviour did not occur on the previous instance.
Steps Taken to Stabilise
- Adjusted Django logging configuration to avoid problematic handlers
- Temporarily suppressed warnings in the WSGI file
However, I’d like to properly understand:
- Whether stdout/stderr is expected to be wrapped this way on this instance
- Why this behaviour differs from my previous instance
- What the recommended logging configuration is to avoid this recursion (e.g. avoiding StreamHandler entirely)
Happy to provide full traceback or for PythonAnywhere Staff to access my codebase if needed.
Thanks in advance