Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

RPyC

From Wikipedia, the free encyclopedia
Python library
This article is about Python library. For the yacht club, seeRPYC.
icon
This articlerelies excessively onreferences toprimary sources. Please improve this article by addingsecondary or tertiary sources.
Find sources: "RPyC" – news ·newspapers ·books ·scholar ·JSTOR
(November 2009) (Learn how and when to remove this message)
RPyC
DeveloperTomer Filiba
Initial release17 December 2005
Stable release
6.0.0 / 23 February 2024; 23 months ago (2024-02-23)[1]
Written inPython
Operating systemCross-platform
TypeRemote Procedure Call
LicenseMIT License
Websiterpyc.readthedocs.org Edit this on Wikidata
Repository

RPyC (pronouncedare-pie-see), orRemotePythonCall, is aPython library forremote procedure calls (RPC), as well asdistributed computing. Unlike regular RPC mechanisms, such asONC RPC,CORBA orJava RMI, RPyC is transparent, symmetric, and requires no special decoration or definition languages. Moreover, it provides programmatic access to any pythonic element, be it functions, classes, instances or modules.

Features

[edit]
  • Symmetric—there is no difference between the client and the server—both can serve. The only different aspect is that the client is usually the side that initiates the action. Being symmetric, for example, allows the client to pass callback functions to the server.
  • Transparent—remote objects look and behave the same as local objects would.
  • Exceptions propagate like local ones
  • Allows for synchronous and asynchronous operation:
    • Synchronous operations return aNetProxy (see below)
    • Asynchronous operations return an AsyncResult, which is likepromise objects
    • AsyncResults can be used as events
  • Threads are supported (though not recommended)
  • UNIX specific: server integration withinetd

Architecture

[edit]

RPyC gives the programmer a slave python interpreter at his or her control. In this essence, RPyC is different from other RPCs, that require registration of resources prior to accessing them. As a result, using RPyC is much more straightforward, but this comes at the expense of security (you cannot limit access). RPyC is intended to be used within a trusted network, there are various schemes includingVPN for achieving this.

Once a client is connected to the server, it has one of two ways to perform remote operations:

  • Themodules property, that exposes the server's modules namespace:doc = conn.modules.sys.path orconn.modules["xml.dom.minidom"].parseString("<some>xml</some>").
  • Theexecute function, that executes the given code on the server:conn.execute("print 'hello world'")

Remote operations return something called aNetProxy, which is an intermediate object that reflects any operation performed locally on it to the remote object. For example, conn.modules.sys.path is a NetProxy for the sys.path object of the server. Any local changes done to conn.modules.sys.path are reflected immediately on the remote object.Note: NetProxies are not used forsimple objects, such as numbers and strings, which are immutable.

Async is a proxy wrapper, meaning, it takes a NetProxy and returns another that wraps it with asynchronous functionality. Operations done to an AsyncNetProxy return something called AsyncResult. These objects have a '.is_ready' predicate, '.result' property that holds the result (or blocks until it arrives), and '.on_ready' callback, which will be called when the result arrives.

Usage

[edit]

Originally, RPyC was developed for managing distributed testing of products over a range of different platforms (all capable of running python). However, RPyC has evolved since then, and now its use cases include:

  • Distributed computing (splitting workload between machines)
  • Distributed testing (running tests that connect multiple platforms and abstracting hardware resources)
  • Remote administration (tweaking config files from one central place, etc.)
  • Tunneling or chaining (crossing over routable network boundaries)

Demo

[edit]
importrpycconn=rpyc.classic.connect("hostname")# assuming a classic server is running on 'hostname'print(conn.modules.sys.path)conn.modules.sys.path.append("lucy")print(conn.modules.sys.path[-1])# a version of 'ls' that runs remotelydefremote_ls(path):ros=conn.modules.osforfilenameinros.listdir(path):stats=ros.stat(ros.path.join(path,filename))print("%d\t%d\t%s"%(stats.st_size,stats.st_uid,filename))remote_ls("/usr/bin")# and exceptions...try:f=conn.builtin.open("/non/existent/file/name")exceptIOError:pass

History

[edit]

RPyC is based on the work ofEyal Lotem (akaLotex) onPyInvoke,[2] which is no longer maintained. The first public release was 1.20, which allowed for symmetric and transparent RPC, but not forasynchronous operation. Version 1.6, while never publicly released, added the concept of 'events', as a means for the server to inform the client. Version 2.X, the first release of which was 2.2, added thread synchronization and theAsync concept, which can be used as a superset of events. Version 2.40 adds theexecute method, that can be used to execute code on the other side of the connection directly.RPyC 3 is a complete rewrite of the library, adding acapability-based security model, explicit services, and various other improvements.

References

[edit]
  1. ^"Releases · tomerfiliba-org/rpyc".github.com. Retrieved2024-04-23.
  2. ^"PyInvoke".

External links

[edit]
Retrieved from "https://en.wikipedia.org/w/index.php?title=RPyC&oldid=1305274250"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp