TTwistedプロトコルを使用するTwisted/Thriftサーバーがあります。私は、クライアントからの接続を、所定のイベントが発生するまで開いておきたいと思う(私はこのイベントをコールバックを介してTwisted reactorによって通知する)。Twistedで倹約の呼び出しをブロックする
class ServiceHandler(object):
interface.implements(Service.Iface)
def listenForEvent(self):
"""
A method defined in my Thrift interface that should block the Thrift
response until my event of interest occurs.
"""
# I need to somehow return immediately to free up the reactor thread,
# but I don't want the Thrift call to be considered completed. The current
# request needs to be marked as "waiting" somehow.
def handleEvent(self):
"""
A method called when the event of interest occurs. It is a callback method
registered with the Twisted reactor.
"""
# Find all the "waiting" requests and notify them that the event occurred.
# This will cause all of the Thrift requests to complete.
ブロッキング・スリフト・コールの錯覚を維持しながらハンドラ・オブジェクトのメソッドから迅速に戻ることができますか?
私はツイスト起動トリガからスリフトハンドラの初期化:最後の呼び出し($client->listenForEvent()
)が正常にそれを上に作ること
$socket = new TSocket('localhost', 9160);
$transport = new TFramedTransport($socket);
$protocol = new TBinaryProtocol($transport);
$client = new ServiceClient($protocol);
$transport->open();
$client->listenForEvent();
:PHPでの私のクライアントはと接続
def on_startup():
handler = ServiceHandler()
processor = Service.Processor(handler)
server = TTwisted.ThriftServerFactory(processor=processor,
iprot_factory=TBinaryProtocol.TBinaryProtocolFactory())
reactor.listenTCP(9160, server)
をサーバーはServiceHandler.listenForEvent
を実行しますが、そのサーバーメソッドがtwisted.internet.defer.Deferred()
インスタンスを返す場合でも、クライアントはすぐに空の配列を受け取り、I geトン例外:メッセージと
例外「TTransportException」「TSocketは: は、ローカルホストからの4バイトの読み込みタイムアウトになりました:ローカルポート38395へ9160」を
これを試しました。私の問題は、クライアントからのTTwistedトランスポートも使用する必要がありますか?私はPHPからTFramedTransportを使用しています。 – ide
遅延したものを返す。問題は、クライアントソケットのタイムアウトがわずか750ミリ秒であったことです。 – ide