我想按函数启动子流程subprocess.call(),我希望主循环等待子进程启动。在
我想用穿线。锁定:
子进程必须作为守护进程运行,因此我将subprocess.call()在线程中。在
但它在subprocess.call(),我认为它只是在等待,因为pyro ns是一个侦听端口的守护程序。我怎样才能做到这一点?在
查看代码,这样更简单:
self.__wait_pyroNS_lock=threading.Lock()
self.__logger.debug('i get wait_pyroNS_lock')
self.__wait_pyroNS_lock.acquire()
pyro_ns = threading.Thread(name='Pyro Name Server', target=self.__Pyro_NameServer, args=(self.__wait_pyroNS_lock,))
pyro_ns.setDaemon(True)
self.__logger.debug('starting thread def self.__Pyro_NameServer')
pyro_ns.start()
self.__wait_pyroNS_lock.acquire() # <--- MAIN LOOP WAITING HERE
self.__wait_pyroNS_lock.release()
def __Pyro_NameServer(self, wait_pyroNS_lock):
try:
self.__logger.debug('def __Pyro_NameServer')
self.__logger.debug('starting pyro-ns')
retcode = subprocess.call("pyro-ns", shell=True) # <--- THREAD STOPS HERE, it doesn't return, so i don't get any code and it's all locked.
if retcode != 0:
self.__logger.debug('command pyro-ns: fail, error code %d' % retcode)
else:
self.__logger.debug('pyro-ns has started')
self.__logger.debug('releasing wait_pyroNS_lock')
wait_pyroNS_lock.release() # <--- IT NEVER RUNS, it releases the lock, the main loop is unlocked
except Exception as e:
self.__logger.error('%s' % str(e))
我决定使用PyRO提供的API。在
相关问题 更多 >
编程相关推荐