我的Python进程因分段错误而关闭,该错误发生在启动后半小时到6-7个小时之间的任何时间。
我无法弄清楚代码的哪一部分导致了分段错误。我试图对代码进行一些更改,但是这些更改没有帮助,因此我添加了faulthandler
来显式转储stacktrace。代码本身没有错误,因为错误日志与代码中的任何错误或异常无关。
Fatal Python error: Aborted
Thread 0x00007f67b515e700 (most recent call first):
File "main_v2.py", line 64 in exec_query
File "main_v2.py", line 101 in record_event
File "main_v2.py", line 212 in v1_feed
File "/usr/local/lib/python3.5/dist-packages/flask_cors/decorator.py", line 128 in wrapped_function
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1799 in dispatch_request
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1813 in full_dispatch_request
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 2292 in wsgi_app
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 2309 in __call__
File "/usr/local/lib/python3.5/dist-packages/werkzeug/serving.py", line 258 in execute
File "/usr/local/lib/python3.5/dist-packages/werkzeug/serving.py", line 270 in run_wsgi
File "/usr/local/lib/python3.5/dist-packages/werkzeug/serving.py", line 328 in handle_one_request
File "/usr/lib/python3.5/http/server.py", line 422 in handle
File "/usr/local/lib/python3.5/dist-packages/werkzeug/serving.py", line 293 in handle
File "/usr/lib/python3.5/socketserver.py", line 681 in __init__
File "/usr/lib/python3.5/socketserver.py", line 354 in finish_request
File "/usr/lib/python3.5/socketserver.py", line 625 in process_request_thread
File "/usr/lib/python3.5/threading.py", line 862 in run
File "/usr/lib/python3.5/threading.py", line 914 in _bootstrap_inner
File "/usr/lib/python3.5/threading.py", line 882 in _bootstrap
Current thread 0x00007f67affff700 (most recent call first):
File "main_v2.py", line 64 in exec_query
File "main_v2.py", line 101 in record_event
File "main_v2.py", line 212 in v1_feed
File "/usr/local/lib/python3.5/dist-packages/flask_cors/decorator.py", line 128 in wrapped_function
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1799 in dispatch_request
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1813 in full_dispatch_request
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 2292 in wsgi_app
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 2309 in __call__
File "/usr/local/lib/python3.5/dist-packages/werkzeug/serving.py", line 258 in execute
File "/usr/local/lib/python3.5/dist-packages/werkzeug/serving.py", line 270 in run_wsgi
File "/usr/local/lib/python3.5/dist-packages/werkzeug/serving.py", line 328 in handle_one_request
File "/usr/lib/python3.5/http/server.py", line 422 in handle
File "/usr/local/lib/python3.5/dist-packages/werkzeug/serving.py", line 293 in handle
File "/usr/lib/python3.5/socketserver.py", line 681 in __init__
File "/usr/lib/python3.5/socketserver.py", line 354 in finish_request
File "/usr/lib/python3.5/socketserver.py", line 625 in process_request_thread
File "/usr/lib/python3.5/threading.py", line 862 in run
File "/usr/lib/python3.5/threading.py", line 914 in _bootstrap_inner
File "/usr/lib/python3.5/threading.py", line 882 in _bootstrap
Thread 0x00007f67bca3e700 (most recent call first):
File "/usr/lib/python3.5/selectors.py", line 376 in select
File "/usr/lib/python3.5/socketserver.py", line 232 in serve_forever
File "/usr/local/lib/python3.5/dist-packages/werkzeug/serving.py", line 612 in serve_forever
File "/usr/local/lib/python3.5/dist-packages/werkzeug/serving.py", line 777 in inner
File "/usr/local/lib/python3.5/dist-packages/werkzeug/serving.py", line 814 in run_simple
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 943 in run
File "main_v2.py", line 224 in run_server
File "main_v2.py", line 241 in main
File "main_v2.py", line 246 in <module>
当我在代码中未使用任何threads
时,我无法理解为什么stacktrace提到了不同的threads
。
File "main_v2.py", line 64 in exec_query
是cur.execute()
来自psycopg2
"main_v2.py", line 101 in record_event
是
调用"main_v2.py", line 212 in
v1_feed
是对上面record_event
函数的调用。这些语句似乎都没有错误。以下是我正在使用的外部模块:
请,感谢您在找出可能导致问题的原因方面的帮助。
更新:我可以通过在Flask app.run()中使用threaded=False
来解决此问题。尽管我不确定为什么可以工作。因此,如果有人可以指出是什么原因造成的,那将会有很大的帮助。