这个问题与A Django Related Question有关
我正在运行一个restlite WSGI应用程序wsgiref.simple_服务器. 我设置了这个设置,以便在serve_forever()方法获得调用之前初始化一些对象。最相关的是这些课程。在
import Queue
import threading
import Deployer
import ParallelRunner
import sys
import subprocess
class DeployManager:
def __init__(self):
self.inputQueue = Queue.Queue()
self.workerThread = DeployManagerWorkerThread(self.inputQueue)
self.workerThread.start()
def addDeployJob(self, appList):
self.inputQueue.put(appList) #make sure this handles the queue being full
def stopWorker(self):
self.workerThread.running = False
def __del__(self):
self.stopWorker()
class DeployManagerWorkerThread(threading.Thread):
def __init__(self, Queue):
super(DeployManagerWorkerThread, self).__init__()
self.queue = Queue
self.running = True
self.deployer = Deployer.Deployer()
self.runner = ParallelRunner.ParallelRunner()
def run(self):
while self.running:
try:
appList = self.queue.get(timeout = 10) #This blocks until something is in the queue
sys.stdout.write('Got deployment job\n')
command = "ssh " + server.sshUsername + "@" + server.hostname + "" + " -i " + server.sshPrivateKeyPath + r" 'bash -s' < " + pathToScript
self.process = subprocess.Popen(command,shell=True ,stdin=subprocess.PIPE, stdout=subprocess.PIPE)
output = process.communicate()[0]
sys.stdout.write(output + '\n')
except Queue.Empty:
pass
sys.stdout.write('DeployManagerWorkerThread exiting\n')
restlite请求是这样设置的
^{pr2}$这会将一个条目放入队列中,然后workerThread将获取该条目并开始处理。但是,打给波彭的电话总是挂断的,我走进这个电话,它似乎挂在一个电话os.fork操作系统()这将“冻结”服务器。当线程到达POpen命令时,主线程在它接受新请求的那一行。我相信服务器正在使用epoll。如果队列中有多个作业,我可以在服务器运行所在的控制台按control-C,主线程将退出(不在等待请求的行),然后线程将能够按预期运行,然后关闭。有什么想法吗?在
我终于明白了。。。我需要在run方法中创建threads对象。我不小心忘记了init方法是从主线程调用的,然后新线程本身永远不会执行init。在
相关问题 更多 >
编程相关推荐