为什么RxPY的TwistedScheduler会引发AlreadyCalled错误?

2024-04-29 04:36:08 发布

您现在位置:Python中文网/ 问答频道 /正文

最小的工作示例——使用RxPY (v.1.2.4)Observable逐字将'Hello world'发送到回显服务器。在

客户

from rx.concurrency.mainloopscheduler import TwistedScheduler
from rx.observable import Observable
from twisted.internet import reactor
from twisted.internet.protocol import ClientFactory
from twisted.protocols.basic import LineReceiver

class RxProtocol(LineReceiver):
    def connectionMade(self):
        Observable.from_list('Hello world'.split(' '), TwistedScheduler(reactor)).subscribe(self.sendLine)

    def lineReceived(self, line):
        print line

if __name__ == '__main__':
    f = ClientFactory()
    f.protocol = RxProtocol
    reactor.connectTCP("localhost", 8000, f)
    reactor.run()

服务器:来自twisted示例的简单echo服务器--echoserv.py

在服务器运行的情况下,启动客户端将提供:

^{pr2}$

我做错什么了?在


Tags: fromimportself服务器示例helloworldtwisted