我有一个非常大(~400k 行)的 Python 函数,我试图通过exec()
称呼。如果我运行以下 Python 脚本:
exec("""def blah()
# 400k lines of IF/THEN/ELSE
""", globals())
blah()
通过从命令行调用Python,它工作得很好。
但是,如果我在 Django 实例中执行相同的操作,它会使服务器崩溃,并且没有任何错误消息或堆栈跟踪,我只能假设这是由于分段错误造成的。
Django runserver 和上面的脚本都在同一个 Conda 环境中运行,并且都有无限的可用堆栈(通过打印出来确认)resource.getrlimit
在姜戈)。
这是我的完整ulimit -a
output:
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 515017
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) unlimited
cpu time (seconds, -t) unlimited
max user processes (-u) 4096
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
启动 Django 服务器的命令序列如下:
source activate <conda env name>
python manage.py runserver
这是导致崩溃的 shell 输入/输出:
(faf) [pymaster@t9dpyths3 faf]$ python manage.py runserver 9000
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
August 04, 2020 - 08:25:19
Django version 3.0.3, using settings 'faf.settings'
Starting development server at http://127.0.0.1:9000/
Quit the server with CONTROL-C.
[04/Aug/2020 08:25:25] "GET /projects/ HTTP/1.1" 200 13847
[04/Aug/2020 08:26:49] "PUT /projects/projectname/ HTTP/1.1" 200 76 # This event triggers the exec
(faf) [pymaster@t9dpyths3 faf]$