파이썬 서버 스크립트에서 두 개의 하위 프로세스를 실행하고 있습니다. 하위 프로세스의 목적은 내 Raspberry Pi에서 비디오를 스트리밍하는 것입니다.다른 명령을 사용하여 하위 프로세스를 종료하는 방법 python
내 질문은 다른 명령을 서버에 보낼 때 하위 프로세스를 죽이는 방법입니다. 현재 Popen()을 사용하여 하위 프로세스를 시작합니다.
이 코드는 서버가 "startStream"명령을 수신 할 때 사용하는 코드입니다. Twisted 라이브러리를 서버 프로토콜로 사용하고 있습니다.
class Echo(Protocol):
def connectionMade(self):
#self.transport.write("""connected""")
self.factory.clients.append(self)
print "clients are ", self.factory.clients
def connectionLost(self, reason):
self.factory.clients.remove(self)
def dataReceived(self, data):
print "data is ", data
if data == "startStream":
p = subprocess.Popen("raspistill --nopreview -w 640 -h 480 -q 5 -o /tmp/stream/pic.jpg -tl 100 -t 9999999 -th 0:0:0 &", shell=True)
pn = subprocess.Popen("LD_LIBRARY_PATH=/usr/local/lib mjpg_streamer -i %s -o %s &" % (x,y), shell=True)
나는 무엇을하고 싶습니다.
if data == "startStream":
p = subprocess.Popen("raspistill --nopreview -w 640 -h 480 -q 5 -o /tmp/stream/pic.jpg -tl 100 -t 9999999 -th 0:0:0 &", shell=True)
pn = subprocess.Popen("LD_LIBRARY_PATH=/usr/local/lib mjpg_streamer -i %s -o %s &" % (x,y), shell=True)
elif data == "stopStream":
os.kill(p.pid)
os.kill(pn.pid)
감사합니다.
'terminate()'? – BusyAnt
문제는 stopStream을 호출 할 때 p 및 pn에 액세스 할 수 없다는 것입니다. 나는 방금 전역 변수로 프로세스를 선언 한 다음 어디서나 액세스 할 수 있지만 Python에서는 작동하지 않는 Java로 작업하고있었습니다. – Oliver
또한 모듈은 속성을 가지고 있지 않다. – Oliver