Django项目频繁触发Maximum recursion level reached问题及虚拟环境咨询
Hey there! Let's tackle your two questions one by one—first the virtual environment query, then that frustrating recursion error.
Absolutely! This is a common and totally valid practice, as long as both apps are compatible with the versions of dependencies in the shared venv.
Sharing a virtual environment saves server resources by avoiding duplicate package installations, and your Apache config (where all three WSGI daemon processes point to /var/www/bigb/venv) is set up correctly for this. The only caveat: if you ever need to upgrade a package for one app, double-check that the other app can work with the new version to avoid dependency conflicts. For your current setup, this isn't the cause of your recursion error.
Looking at your error trace, the issue originates in pandas/io/json/json.py at line 99 (the write method). Recursion overflow almost always means a function is calling itself indefinitely (no termination condition) or there's a circular reference in the data being processed. Here's how to dig into it:
First, focus on the problematic view and pandas usage
The error happens when hitting http://192.168.1.25/bigflow/Getprstatus/, so start by inspecting the code in this view:
- Look for places where you're using pandas' JSON serialization methods (like
to_json()) or passing data to pandas that might have circular references. For example, if you're trying to serialize a Django model instance directly, reverse foreign key relationships can create loops (e.g., aParentmodel has a foreign key toChild, which has a reverse relation back toParent). - Instead of passing full model instances to pandas, try extracting only the fields you need into a plain dictionary first. Or use Django's built-in
serializers.serialize()to handle model data safely before passing it to pandas.
Check for edge cases in request data
Since the error happens frequently but not constantly, it's likely triggered by specific request parameters or database records. Add logging to the Getprstatus view to record:
- The incoming request parameters
- The specific database objects being processed when the error occurs
This will help you identify if certain data (like a record with self-referential relationships) is causing the loop.
Rule out pandas version bugs
Your setup uses Python 3.5.2 and Django 2.0.3—if your pandas version is outdated, it might have a known bug in JSON serialization that causes infinite recursion. The last pandas version compatible with Python 3.5 is 0.25.3; try upgrading to that version (run pip install pandas==0.25.3 in your venv) to see if the error goes away.
Verify Apache WSGI config (less likely, but worth checking)
Your WSGI config sets up separate daemon processes for each app, which is good practice. The processes=2 threads=15 settings are reasonable for most workloads, and this config isn't directly causing recursion issues. That said, if you've added any global mutable state to your apps (like global variables that are modified during requests), this could cause unexpected behavior in multi-threaded environments—but this is a less common culprit here.
Debugging tip
Try reproducing the error locally: use the same request parameters that triggered the error on the server, and run the view code in a debugger. This will let you step through the pandas JSON write method and see exactly where the infinite recursion starts.
内容的提问来源于stack exchange,提问作者selvakumar

