2011-01-06 220 views
2

我寫了一個簡單的扭曲的服務器 -Python的扭曲守護

from twisted.internet import reactor 
from twisted.internet import protocol 
from twisted.web import server, resource 
from twisted.internet import reactor 

class Index(resource.Resource): 
    isLeaf = True 
    def render_GET(self, request): 
     args = request.args 
     print 'Args: %s' %(repr(args)) 

print 'Serving on PORT: 8090' 
site = server.Site(Index()) 
reactor.listenTCP(8090, site) 
reactor.run() 

這個運行在127.0.0.1:8090罰款。請注意,這將在終端(前臺)中運行,當我使用nohup & ctrl+Z在後臺運行該進程時。服務器不響應請求。我應該怎麼做,以守護這個扭曲的服務器

+0

你是否真的在背景中,或者只是用ctrl + z暫停它? – nmichaels 2011-01-06 17:56:58

+0

以及我試過`ctrl + z`。我該如何對它進行deamonize? – 2011-01-06 17:58:38

+3

輸入「ctrl + z」後,在shell中鍵入「bg」。這將恢復被暫停的過程作爲後臺作業 – Rakis 2011-01-06 18:54:41

回答

3

正如nmichael和Rakis已經提到的,在「ctrl + z」之後鍵入「bg」以恢復暫停過程作爲後臺作業。

要直接運行它作爲後臺作業,類型

python myserver.py & 

要直接作爲後臺作業運行它時,你註銷不會停止,類型

nohup python myserver.py & 

還要注意的是nohup,是不是真正的deamonization。看到這裏的差異:What's the difference between nohup and a daemon?

如果你真的想deamonize您的扭曲的服務器,最好的選擇是使用twistd馬克Loeser回答。