최소한의 예는 질문의 명확성을 높이는 데 도움이됩니다. 그러나 수년간의 Twisted 경험을 바탕으로, 저는 교육적인 추측을 가지고 있습니다. 나는 당신이 다음과 같은 프로그램을 작성했다고 생각합니다 :
from twisted.internet import endpoints, reactor, protocol
factory = protocol.Factory()
factory.protocol = protocol.Protocol
endpoint = endpoints.TCP4ServerEndpoint(reactor, 8000)
d = endpoint.listen(factory)
def listenFailed(reason):
reactor.stop()
d.addErrback(listenFailed)
reactor.run()
당신은 올바른 길을 가고 있습니다. 불행히도 주문 문제가 있습니다. 이유는 reactor.stop
이 ReactorNotRunning
으로 실패하기 때문에 listen
지연이 '전에'실패한 것입니다. 이는 reactor.run
입니다. 즉, d.addErrback(listenFailed
을 수행 할 때까지 이미 실패했습니다. 따라서 listenFailed
이 바로 호출되었습니다.
여기에는 여러 가지 해결책이 있습니다. , twistd -y thisfile.tac
또 다른 옵션은 서비스를 기반으로하는 낮은 수준의 기능을 사용하는 것처럼이 twistd
를 사용하여 실행됩니다
from twisted.internet import endpoints, reactor, protocol
from twisted.application.internet import StreamServerEndpointService
from twisted.application.service import Application
application = Application("Some Kind Of Server")
factory = protocol.Factory()
factory.protocol = protocol.Protocol
endpoint = endpoints.TCP4ServerEndpoint(reactor, 8000)
service = StreamServerEndpointService(endpoint, factory)
service.setServiceParent(application)
, reactor.callWhenRunning
: 하나는 .tac 파일을 작성하고 서비스를 사용하는 것입니다
from twisted.internet import endpoints, reactor, protocol
factory = protocol.Factory()
factory.protocol = protocol.Protocol
endpoint = endpoints.TCP4ServerEndpoint(reactor, 8000)
def listen():
d = endpoint.listen(factory)
def listenFailed(reason):
reactor.stop()
d.addErrback(listenFailed)
reactor.callWhenRunning(listen)
reactor.run()
greate 답변 해 주셔서 감사합니다. –