Note that there are some explanatory texts on larger screens.

plurals
  1. PONo shell prompt message, just a blinking cursor after starting a Python script as a daemon?
    primarykey
    data
    text
    <ul> <li>python-daemon-1.5.2-1.el6.noarch</li> </ul> <p>Below is the script that I received from a developer:</p> <pre class="lang-py prettyprint-override"><code>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) </code></pre> <p>As you can see, he's using the <a href="http://docs.python.org/2/library/threading.html" rel="nofollow">threading</a> module to make it can be run as a daemon.</p> <p>I'm going to switch to use the <a href="http://www.python.org/dev/peps/pep-3143/" rel="nofollow">daemon</a> library follow <a href="http://www.gavinj.net/2012/06/building-python-daemon-process.html" rel="nofollow">this</a> blog post.</p> <p>Here's my first try:</p> <pre class="lang-py prettyprint-override"><code>from daemon import runner import logging import time import threading import multiprocessing, os, signal, time, Queue import time from suds.client import Client from hotqueue import HotQueue from config import config class Mail(): def __init__(self): self.stdin_path = '/dev/null' self.stdout_path = '/dev/tty' self.stderr_path = '/dev/tty' self.pidfile_path = '/var/run/sendmailworker/sendmailworker.pid' self.pidfile_timeout = 1 def run(self): while True: queue = HotQueue(config['redis_hotqueue_list'], host=config['redis_host'], port=int(config['redis_port']), password=config['redis_pass'], charset=r"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, '', '', ''); logger.debug("result") #sleep(50) mail = Mail() logger = logging.getLogger("sendmailworker") logger.setLevel(logging.INFO) formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") handler = logging.FileHandler("/var/log/sendmailworker/sendmailworker.log") handler.setFormatter(formatter) logger.addHandler(handler) daemon_runner = runner.DaemonRunner(mail) daemon_runner.daemon_context.files_preserve=[handler.stream] daemon_runner.do_action() </code></pre> <p>It works but I have to press the <kbd>Ctrl</kbd>-<kbd>C</kbd> to get the shell prompt after starting:</p> <p><strong><code>/etc/init.d/sendmailworker start</code></strong></p> <pre class="lang-sh prettyprint-override"><code>Starting server # started with pid 2586 ^C # </code></pre> <p>How can I get rid of this problem?</p> <hr> <p>Append an ampersand doesn't help:</p> <pre class="lang-sh prettyprint-override"><code># /etc/init.d/sendmailworker start &amp; [1] 4094 # Starting server started with pid 4099 ^C [1]+ Done /etc/init.d/sendmailworker start # </code></pre> <hr> <p>As @Celada pointed out: actually, I already had my shell prompt, but it doesn't display <code>[root@hostname ~]#</code> as usual, just a blinking cursor. Simple pressing <kbd>Enter</kbd> make my shell prompt reappear. So the question should be: how to make the <code>started with pid xxxxx</code> come first, at the same line with <code>Starting server</code>, then display my shell prompt? </p> <hr> <p>The <code>stop</code> function is working fine:</p> <pre class="lang-sh prettyprint-override"><code>[root@hostname ~]# /etc/init.d/sendmailworker stop Stopping server Terminating on signal 15 [root@hostname ~]# </code></pre> <p>How can I do the similar for the <code>start</code> function? Something like this:</p> <pre class="lang-sh prettyprint-override"><code>[root@hostname ~]# /etc/init.d/sendmailworker start Starting server started with pid 30624 [root@hostname ~]# </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload