Python 的 RPC 世界中的远程对象返回另一个远程对象
我基本上熟悉Python中可用的RPC解决方案:XML-RPC和Pyro。我可以通过在服务器端绑定它来创建一个远程对象,然后我可以在客户端获取可以操作的代理对象。当我在远程对象上调用某些方法(例如 proxy.get_file() )时,rpc 机制会尝试序列化结果对象(在本例中为文件)。这通常是预期的行为,但我需要的是获取一个文件对象作为另一个远程代理对象,而不是将其传输到客户端:
afile_proxy = proxy.get_file()
而不是:
afile = proxy.get_file()
我可以在服务器端重新绑定此对象并在客户端处理这种情况但这需要一些样板代码。有没有一个机制/库可以为我做这件事?例如,它可以使对象保持远程状态,直到它们成为原始对象为止。
I am basically familiar with RPC solutions available in Python: XML-RPC and Pyro. I can make an remote object by binding it on the server-side and then I can get proxy object on the client side on which I can operate. When I call some method on remote object e.g. proxy.get_file() then the rpc mechanism tries to serialize a resultant object (a file in this case). This is usually expected behavior, but what I need is to get a file object as another remote proxy object instead of getting it transferred to client side:
afile_proxy = proxy.get_file()
Instead of:
afile = proxy.get_file()
I could rebind this object on server-side and handle such case on the client side but this would require some boiler-plate code. Is there a mechanism/library that would do this for me? It could for example keep objects remote until they are primitive ones.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我找到了一个完全满足我需要的库:RPyC。来自 intro:
无论如何,感谢您指出“参考”术语。 :)
I have found a library that does exactly what I need: RPyC. From intro:
Anyway, thanks for pointing out a 'reference' term. :)
我参与开发一个新的远程对象交互框架 Versile Python (VPy),它执行与您列出的那些。 VPy 正在开发中,当前版本主要用于测试,但请随意查看。
有两种方法可以执行您使用 VPy 描述的远程 I/O 类型。一种是使用远程 本机对象 引用,例如类似的文件对象Pyro/RPyC 并访问这些对象,就像它们是本地对象一样。
另一种选择是使用 VPy 远程 stream 框架,这是相当有效的灵活,可以配置为执行双向流和操作,例如远程重新定位或截断流。第二种方法的优点是它支持异步 I/O,并且流框架分割数据传输以减少往返延迟的影响。
I am involved in developing a new remote-object interaction framework Versile Python (VPy) which performs similar functions as the ones you have listed. VPy is in development with the current releases primarily intended for testing, however feel free to take a look.
There are two ways you could perform the type of remote I/O you are describing with VPy. One is to use remote native object references to e.g. file objects similar to Pyro/RPyC and access those objects similar to if they were local.
Another option is to use the VPy remote stream framework which is quite flexible and can be configured to perform bi-directional streaming and operations such as remotely repositioning or truncating the stream. The second approach has the advantage it enables asynchronous I/O plus the stream framework splits up data transmission in order to reduce the effects of round-trip latency.
并在 API 中定义什么是
FileProxy
对象。这完全取决于客户端需要使用代理做什么。葛名字?删除它吗?获取其内容?如果您只想跟踪稍后要处理的内容,您甚至可以不用引用(也许是 URL)。这就是在网络上对所有嵌入内容(例如图像)所做的事情。
And define in the API what a
FileProxy
object is. It all depends on what the client needs to do with the proxy. Ge the name? Delete it? Get its contents?You could even get away with a reference (a URL, maybe) if all you want is to keep track of something you want to process later. It's what's done on the web with all embedded content, like images.