为了运行单元测试,我想使用以下命令用Python设置一个本地SMTP服务器:
python -c "import smtpd, asyncore; smtpd.DebuggingServer(('127.0.0.1', 8025), None); asyncore.loop()" > test.log &但是不会将任何输出写入test.log文件。
但是,当我运行以下命令时,输出确实会被写入:
python -c "import smtpd, asyncore; smtpd.DebuggingServer(('127.0.0.1', 8025), None); asyncore.loop()" > test.log` or `python -c "print('TEST')" > test.log &这和asyncore有关系吗?或者这是怎么回事?
我和Python 3.6在Mac上。
编辑:我尝试通过以下命令使用aiosmtpd模块来启动服务器:
python -m aiosmtpd -n > test.log &这会产生相同的结果。因此,这似乎只在处理多处理循环时才是一个问题
编辑2:简化了一些命令,删除了nohup和sudo,仍然存在相同的问题
编辑3:为了澄清,一旦我运行服务器,我在解释器中运行以下命令来发送消息:
import smtplib; server = smtplib.SMTP(host='127.0.0.1', port=8025); server.ehlo(); server.sendmail("sender@test.test", "receiver@test.test", "MESSAGE") 编辑4:我甚至尝试过在一个文件中运行上面的asyncore.loop():
python test.py > test.log &还是不走运
发布于 2019-11-08 15:30:45
问题不在于nohup,而在于sudo。sudo一定是询问你的密码,然后又取消了,因为它不能在后台询问你,所以,重新排序你的命令并激活sudo后台标志...
sudo -b nohup python -c "import smtpd, asyncore; smtpd.DebuggingServer(('127.0.0.1', 587), None); asyncore.loop()" > test.logsudo -b取代了&,因为它将在后台运行python。
https://stackoverflow.com/questions/58752532
复制相似问题