出于运行单元测试的目的,我想使用以下命令使用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,None); asyncore.loop()" > test.log` or `python -c "print('TEST')" > test.log &
这与异步现象有关吗?还是这里发生了什么?
我在Mac OSX上使用Python 3.6
。
编辑:
我尝试将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 &
仍然没有运气