服務器系統:
CentOS release 6.8 (Final)
python資訊:
Python 3.7.2
uwsgi資訊
2.0.18
框架:
Django 2.1
問題:python的ssl是可以的,通過runserver是可以發送電子郵件的,但是當放入uwsgi環境里面不行,報錯資訊如下:
!!! uWSGI process 10068 got Segmentation Fault !!!
*** backtrace of 10068 ***
/usr/local/python3/bin/uwsgi(uwsgi_backtrace+0x29) [0x4c0309]
/usr/local/python3/bin/uwsgi(uwsgi_segfault+0x21) [0x4c0491]
/lib64/libc.so.6(+0x32510) [0x7ff68abd0510]
/usr/lib64/libcrypto.so.1.0.0(X509_VERIFY_PARAM_set_hostflags+0x4) [0x7ff682c60d54]
/home/python_envs/operation/lib/python3.7/lib-dynload/_ssl.cpython-37m-x86_64-linux-gnu.so(+0xef37) [0x7ff681238f37]
/usr/local/python3/bin/uwsgi() [0x54e2a8]
/usr/local/python3/bin/uwsgi(_PyMethodDef_RawFastCallKeywords+0x248) [0x50db38]
/usr/local/python3/bin/uwsgi(_PyCFunction_FastCallKeywords+0x23) [0x50e9d3]
/usr/local/python3/bin/uwsgi(_PyEval_EvalFrameDefault+0x4807) [0x591147]
/usr/local/python3/bin/uwsgi(_PyEval_EvalCodeWithName+0x1ba) [0x595afa]
/usr/local/python3/bin/uwsgi(_PyFunction_FastCallDict+0x144) [0x50e4b4]
/usr/local/python3/bin/uwsgi(_PyObject_Call_Prepend+0x8b) [0x50f58b]
/usr/local/python3/bin/uwsgi() [0x54d304]
/usr/local/python3/bin/uwsgi() [0x54f0b3]
/usr/local/python3/bin/uwsgi(_PyObject_FastCallKeywords+0x9e) [0x50ea8e]
/usr/local/python3/bin/uwsgi(_PyEval_EvalFrameDefault+0x46e5) [0x591025]
/usr/local/python3/bin/uwsgi(_PyEval_EvalCodeWithName+0x51f) [0x595e5f]
/usr/local/python3/bin/uwsgi(_PyFunction_FastCallKeywords+0x100) [0x50e2a0]
/usr/local/python3/bin/uwsgi(_PyEval_EvalFrameDefault+0x1404) [0x58dd44]
/usr/local/python3/bin/uwsgi(_PyEval_EvalCodeWithName+0x1ba) [0x595afa]
/usr/local/python3/bin/uwsgi(_PyFunction_FastCallDict+0x3ab) [0x50e71b]
/usr/local/python3/bin/uwsgi(_PyObject_Call_Prepend+0x8b) [0x50f58b]
/usr/local/python3/bin/uwsgi() [0x552721]
/usr/local/python3/bin/uwsgi() [0x54f10b]
/usr/local/python3/bin/uwsgi(PyObject_Call+0x52) [0x50fae2]
/usr/local/python3/bin/uwsgi(_PyEval_EvalFrameDefault+0x1d30) [0x58e670]
/usr/local/python3/bin/uwsgi() [0x50e0da]
/usr/local/python3/bin/uwsgi(_PyEval_EvalFrameDefault+0x86c) [0x58d1ac]
/usr/local/python3/bin/uwsgi() [0x50e0da]
/usr/local/python3/bin/uwsgi(_PyEval_EvalFrameDefault+0x86c) [0x58d1ac]
/usr/local/python3/bin/uwsgi(_PyEval_EvalCodeWithName+0x1ba) [0x595afa]
/usr/local/python3/bin/uwsgi(_PyFunction_FastCallKeywords+0x100) [0x50e2a0]
/usr/local/python3/bin/uwsgi(_PyEval_EvalFrameDefault+0x86c) [0x58d1ac]
/usr/local/python3/bin/uwsgi(_PyEval_EvalCodeWithName+0x1ba) [0x595afa]
/usr/local/python3/bin/uwsgi(_PyFunction_FastCallKeywords+0x100) [0x50e2a0]
/usr/local/python3/bin/uwsgi(_PyEval_EvalFrameDefault+0x1404) [0x58dd44]
/usr/local/python3/bin/uwsgi() [0x50e0da]
/usr/local/python3/bin/uwsgi(_PyFunction_FastCallDict+0x3fb) [0x50e76b]
/usr/local/python3/bin/uwsgi(_PyEval_EvalFrameDefault+0x1d30) [0x58e670]
/usr/local/python3/bin/uwsgi() [0x50e0da]
/usr/local/python3/bin/uwsgi(_PyEval_EvalFrameDefault+0x69e) [0x58cfde]
/usr/local/python3/bin/uwsgi(_PyEval_EvalCodeWithName+0x1ba) [0x595afa]
/usr/local/python3/bin/uwsgi(_PyFunction_FastCallKeywords+0x100) [0x50e2a0]
/usr/local/python3/bin/uwsgi(_PyEval_EvalFrameDefault+0x459a) [0x590eda]
/usr/local/python3/bin/uwsgi() [0x50e0da]
/usr/local/python3/bin/uwsgi(_PyFunction_FastCallDict+0x75) [0x50e3e5]
/usr/local/python3/bin/uwsgi(_PyObject_Call_Prepend+0x8b) [0x50f58b]
/usr/local/python3/bin/uwsgi() [0x54c2c4]
/usr/local/python3/bin/uwsgi(_PyObject_FastCallKeywords+0x9e) [0x50ea8e]
/usr/local/python3/bin/uwsgi(_PyEval_EvalFrameDefault+0x46e5) [0x591025]
/usr/local/python3/bin/uwsgi(_PyEval_EvalCodeWithName+0x1ba) [0x595afa]
/usr/local/python3/bin/uwsgi(_PyFunction_FastCallKeywords+0x100) [0x50e2a0]
/usr/local/python3/bin/uwsgi(_PyEval_EvalFrameDefault+0x459a) [0x590eda]
/usr/local/python3/bin/uwsgi() [0x50e0da]
/usr/local/python3/bin/uwsgi(_PyFunction_FastCallDict+0x75) [0x50e3e5]
/usr/local/python3/bin/uwsgi(_PyObject_Call_Prepend+0x8b) [0x50f58b]
/usr/local/python3/bin/uwsgi() [0x54c2c4]
/usr/local/python3/bin/uwsgi(_PyObject_FastCallKeywords+0x9e) [0x50ea8e]
/usr/local/python3/bin/uwsgi(_PyEval_EvalFrameDefault+0x46e5) [0x591025]
/usr/local/python3/bin/uwsgi(_PyEval_EvalCodeWithName+0x1ba) [0x595afa]
/usr/local/python3/bin/uwsgi(_PyFunction_FastCallKeywords+0x100) [0x50e2a0]
/usr/local/python3/bin/uwsgi(_PyEval_EvalFrameDefault+0x459a) [0x590eda]
/usr/local/python3/bin/uwsgi() [0x50e0da]
/usr/local/python3/bin/uwsgi(_PyFunction_FastCallDict+0x75) [0x50e3e5]
*** end of backtrace ***
DAMN ! worker 6 (pid: 10068) died :( trying respawn ...
Respawned uWSGI worker 6 (new pid: 12244)
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x1b927b0 pid: 12244 (default app)
uwsgi配置如下:
# uwsig使用組態檔啟動
[uwsgi]
# 專案目錄
uid = root
chdir = /home/wwwroot/operation/operation
# 指定專案的application
module= operation.wsgi:application
virtualenv = /home/python_envs/operation/
#home = /home/python_envs/operation/
touch-reload= /home/wwwroot/operation/operation
# 指定sock的檔案路徑
#socket=127.0.0.1:9092
socket=/run/uwsgi/operation.socket
# 行程個數
processes = 4
workers=8
# 指定靜態檔案
#istatic-map=/static=/hostatic
# 啟用主行程
master=true
# 自動移除unix Socket和pid檔案當服務停止的時候
vacuum=true
# 序列化接受的內容,如果可能的話
enable-threads = true
enable-threads=true
lazy=true
vacuum = true
thunder-lock=true
# 啟用執行緒
enable-threads=true
#threads=20
# 設定自中斷時間
harakiri-verbose = true
harakiri=300
http-keepalive = 1
add-header = Connection: Keep-Alive
disable-logging = true
reload-mercy = 5
vacuum = true //退出、重啟時清理檔案
max-requests = 500
limit-as = 65535
buffer-size = 68718428160
# 設定緩沖
post-buffering=4096
# 設定日志目錄
daemonize=/home/wwwlogs/operation.log
disable-logging=/home/wwwlogs/operation_error.log
# 保存uwsgi的狀態
stats=/run/uwsgi/operation.status
# 行程id,用于重啟,停止uwsgi
pidfile=/run/uwsgi/operation.pid
env LANG="en_US.UTF-8"
env LANGUAGE="en_US.UTF-8"
麻煩專業人士幫忙解答一下,謝謝
uj5u.com熱心網友回復:
大神們,求解救啊,這個問題困擾我很久了uj5u.com熱心網友回復:
我沒用過 uwsgi
看了資料,不知道是否和這個配置引數有關?
reload-mercy
設定在平滑的重啟(直到接收到的請求處理完才重啟)一個作業子行程中,等待這個作業結束的最長秒數。
--reload-mercy 8
uj5u.com熱心網友回復:
我按照您說的修改了對應的引數,還是不能解決問題
uj5u.com熱心網友回復:
感覺應該是超時后,系統kill 掉行程。發郵件時間大概耗時多長?
發郵件的動作是 啟動 web服務就激發嗎?
uj5u.com熱心網友回復:
enable-threads = trueenable-threads=true
有2個一樣的引數, 有影響嗎?
uwsgi 能在啟動完成后,列印一下配置嗎? 看看關鍵配置是否都生效了?
uj5u.com熱心網友回復:
enable-threads = true
enable-threads=true
有2個一樣的引數, 有影響嗎?
uwsgi 能在啟動完成后,列印一下配置嗎? 看看關鍵配置是否都生效了?
應該不影響的
啟動日志如下:
*** Starting uWSGI 2.0.18 (64bit) on [Fri Apr 19 16:01:22 2019] ***
compiled with version: 4.4.7 20120313 (Red Hat 4.4.7-23) on 08 March 2019 05:28:46
os: Linux-2.6.32-696.6.3.el6.x86_64 #1 SMP Wed Jul 12 14:17:22 UTC 2017
nodename: iZbp11scm29o20t4a5c84nZ
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /home/wwwroot/operation/operation
writing pidfile to /run/uwsgi/operation.pid
detected binary path: /home/python_envs/operation/bin/uwsgi
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
chdir() to /home/wwwroot/operation/operation
your processes number limit is 65535
limiting address space of processes...
your process address space limit is 68718428160 bytes (65535 MB)
your memory page size is 4096 bytes
detected max file descriptor number: 65535
lock engine: pthread robust mutexes
thunder lock: enabled
uwsgi socket 0 bound to UNIX address /run/uwsgi/operation.socket fd 3
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
Python version: 3.7.2 (default, Mar 7 2019, 18:25:40) [GCC 4.4.7 20120313 (Red Hat 4.4.7-23)]
Set PythonHome to /home/python_envs/operation/
Python main interpreter initialized at 0x1de7820
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 7770006 bytes (7587 KB) for 80 cores
*** Operational MODE: preforking+threaded ***
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 11526)
spawned uWSGI worker 1 (pid: 11527, cores: 10)
spawned uWSGI worker 2 (pid: 11528, cores: 10)
spawned uWSGI worker 3 (pid: 11529, cores: 10)
spawned uWSGI worker 4 (pid: 11530, cores: 10)
spawned uWSGI worker 5 (pid: 11531, cores: 10)
spawned uWSGI worker 6 (pid: 11532, cores: 10)
spawned uWSGI worker 7 (pid: 11533, cores: 10)
spawned uWSGI worker 8 (pid: 11534, cores: 10)
*** Stats server enabled on /run/uwsgi/operation.status fd: 23 ***
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x1de7820 pid: 11531 (default app)
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x1de7820 pid: 11529 (default app)
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x1de7820 pid: 11528 (default app)
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x1de7820 pid: 11533 (default app)
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x1de7820 pid: 11532 (default app)
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x1de7820 pid: 11534 (default app)
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x1de7820 pid: 11530 (default app)
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x1de7820 pid: 11527 (default app)
uj5u.com熱心網友回復:
發郵件程序應該不超過60秒吧?uj5u.com熱心網友回復:
發郵件程序應該不超過60秒吧?
您是指“your mercy for graceful operations on workers is 60 seconds”嗎?
后來我將其設定成8秒 還是同樣的問題
uj5u.com熱心網友回復:
uwsgi配置一般需要注意,如果程式里用了多執行緒,那么需要配置啟用子執行緒,并設定子執行緒數量,否則django就變成單執行緒的了,會阻塞,發郵件我建議你直接使用django里的EmailMultiAlternatives,我這邊的django專案也是用uwsgi部署的,郵件發送很正常uj5u.com熱心網友回復:
uwsgi配置一般需要注意,如果程式里用了多執行緒,那么需要配置啟用子執行緒,并設定子執行緒數量,否則django就變成單執行緒的了,會阻塞,發郵件我建議你直接使用django里的EmailMultiAlternatives,我這邊的django專案也是用uwsgi部署的,郵件發送很正常
uj5u.com熱心網友回復:
我直接用的send_email方法 你有沒有試過多執行緒的配置 uwsgi配置一般需要注意,如果程式里用了多執行緒,那么需要配置啟用子執行緒,并設定子執行緒數量,否則django就變成單執行緒的了,會阻塞,發郵件我建議你直接使用django里的EmailMultiAlternatives,我這邊的django專案也是用uwsgi部署的,郵件發送很正常
uj5u.com熱心網友回復:
ssl?我看你也沒有配置https啊,而且發郵件就是連smtp服務器傳資料,跟ssl沒關系吧。給你看下我這邊的配置,你參考一下[uwsgi]
# 專案目錄
chdir=/home/wls81/mywebsuite/
# 指定專案的application
module=mywebsuite.wsgi:application
# 指定sock的檔案路徑
socket=/home/wls81/script_tpf/uwsgi.sock
# 行程個數
processes = 1
threads = 20
pidfile=/home/wls81/script_tpf/uwsgi.pid
# 指定IP埠
http=172.16.101.181:8888
# 啟用主行程
master=true
# 自動移除unix Socket和pid檔案當服務停止的時候
vacuum=true
# 啟用執行緒
enable-threads=true
# 設定日志目錄
daemonize=/home/wls81/script_tpf/uwsgi.log
# 啟動uwsgi的用戶名和用戶組
uid=root
gid=root
# 設定自中斷時間
harakiri=30
# 設定緩沖
post-buffering=4096
uj5u.com熱心網友回復:
ssl?我看你也沒有配置https啊,而且發郵件就是連smtp服務器傳資料,跟ssl沒關系吧。給你看下我這邊的配置,你參考一下
[uwsgi]
# 專案目錄
chdir=/home/wls81/mywebsuite/
# 指定專案的application
module=mywebsuite.wsgi:application
# 指定sock的檔案路徑
socket=/home/wls81/script_tpf/uwsgi.sock
# 行程個數
processes = 1
threads = 20
pidfile=/home/wls81/script_tpf/uwsgi.pid
# 指定IP埠
http=172.16.101.181:8888
# 啟用主行程
master=true
# 自動移除unix Socket和pid檔案當服務停止的時候
vacuum=true
# 啟用執行緒
enable-threads=true
# 設定日志目錄
daemonize=/home/wls81/script_tpf/uwsgi.log
# 啟動uwsgi的用戶名和用戶組
uid=root
gid=root
# 設定自中斷時間
harakiri=30
# 設定緩沖
post-buffering=4096
因為我發現一個問題,如果使用25埠發送郵件,是連接163服務器超時,如果使用465,不開啟ssl方式也是不行,如果使用ssl方式,uwsgi執行緒直接就掛了
uj5u.com熱心網友回復:
【解決了!!!】我也遇到了同樣的問題,在Stack Overflow上發現了解決方案。如果你是pip install uwsgi的嗎,如果是的話,卸載掉它,然后pip install pyuwsgi。Pyuwsgi can be used instead of building uWSGI from source. It is a wheel, but excludes the SSL plugin so it should workaround the incompatibility.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/105027.html
上一篇:小白求教,關于時間戳問題
