twisted运行异步示例并在Python提示符下建立连接?

2024-05-18 10:54:08 发布

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

ldaptor项目在交互式Python提示符处有一些基于Twisted的示例代码。不过,在[1]点上,如果因为某个函数已被弃用而实际尝试在提示符处执行操作,则该示例将中断--twisted.trial.util.deferredResult()。有趣的是,这显然让reactor运行,建立连接,并返回延迟的结果(LDAPClient协议实例),这可以在交互式Python解释器中进行操作。在

我的问题是,有没有什么现代的方法来做这种事情,只是为了举例或者只是为了试验?我可以马上做这样的事情:

>>> from ldaptor.protocols.ldap.ldapclient import LDAPClient
>>> from twisted.internet import reactor
>>> from twisted.internet.endpoints import clientFromString, connectProtocol
>>> e = clientFromString(reactor, "tcp:host=localhost:port=10389")
>>> e
<twisted.internet.endpoints.TCP4ClientEndpoint at 0xb452e0c>
>>> d = connectProtocol(e, LDAPClient)
>>> d
<Deferred at 0xb34656c>

但是我想不出任何方法来运行rector并将延迟的结果返回到交互式提示符。有可能吗?钩针项目会有帮助吗?在

[1]https://ldaptor.readthedocs.org/en/latest/addressbook-example.html#searching


Tags: 项目方法fromimport示例twisted事情internet
1条回答
网友
1楼 · 发布于 2024-05-18 10:54:08

你可以试试:

  • python -m twisted.conch.stdio
  • pip install bpython urwid; bpython-urwid reactor select

每一个都会给你一个增强的Python提示,在后台运行一个Twisted reactor。前者本机支持Deferred,但后者功能丰富得多。在

相关问题 更多 >