没有shell提示消息,只是启动Python脚本作为守护进程后闪烁的光标?

2024-06-16 09:05:14 发布

您现在位置:Python中文网/ 问答频道 /正文

  • python-daemon-1.5.2-1.el6.noarch

下面是我从开发人员那里收到的脚本:

import threading
import multiprocessing, os, signal, time, Queue
import time
from suds.client import Client
from hotqueue import HotQueue
from config import config

queue = HotQueue(config['redis_hotqueue_list'], host=config['redis_host'], port=int(config['redis_port']),password=config['redis_pass'], charset="utf-8",db=0)
@queue.worker()
def sendMail(item):    
    key = item[0]        
    domain = item[1]
    fromemail = item[2]
    fromname = item[3]
    subject = item[4]
    content = item[5]
    toemail = item[6]            
    cc = item[7]
    bcc = item[8]
    replyto = item[9]

    # Convert to string variable
    url = config['sendmail_tmdt_url']
    client = Client(url)        
    client.service.send_mail(key,domain, fromemail,subject, content, toemail,fromname, '','','');               
for i in range(10):
    t = threading.Thread(target=sendMail)
    t.setDaemon(True)
    t.start()
while True:
    time.sleep(50)

如您所见,他使用threading模块使其可以作为守护进程运行。在

{{3}我要使用博客{2}来跟随^我的博客}。在

这是我的第一次尝试:

^{pr2}$

它可以工作,但我必须在启动后按Ctrl-C来获得shell提示:

/etc/init.d/sendmailworker start

Starting server
# started with pid 2586
^C
#

我怎样才能解决这个问题?在


附加一个和号没有帮助:

# /etc/init.d/sendmailworker start &
[1] 4094
# Starting server
started with pid 4099
^C
[1]+  Done                    /etc/init.d/sendmailworker start
#

正如@Celada指出的:实际上,我已经有了shell提示符,但它并不像往常一样显示[root@hostname ~]#,只是一个闪烁的光标。只需按回车键即可重新出现“我的shell”提示。所以问题应该是:如何让started with pid xxxxx先出现在Starting server的同一行,然后显示我的shell提示符?在


stop函数工作正常:

[root@hostname ~]# /etc/init.d/sendmailworker stop
Stopping server
Terminating on signal 15
[root@hostname ~]# 

如何对start函数执行类似的操作?像这样:

[root@hostname ~]# /etc/init.d/sendmailworker start
Starting server
started with pid 30624
[root@hostname ~]# 

Tags: importredisconfigserverinitwithetcroot
1条回答
网友
1楼 · 发布于 2024-06-16 09:05:14

你可以通过改变得到你期望的爱情

self.stdout_path = '/dev/tty'
self.stderr_path = '/dev/tty'

收件人:

^{pr2}$

我建议在您的案例中使用shell脚本编写init脚本。在

仅供参考,除了source code,我找不到runner的任何文档。在

相关问题 更多 >