Remote python Call (RPYC) is a Python library used to implement RPC and distributed computing tools. Support for synchronous and asynchronous operations, callbacks and remote services, and transparent object proxies
Function
Transparent-accesses remote objects if they are native to existing code that can be seamlessly with local or remote objects.
Symmetry-the protocol itself is completely symmetric, which means that it can be requested for both the client and the server. This causes the server to invoke the client callback, among other things.
Synchronous and asynchronous operations
Platform Independent-32/64 bit, small/big-windows/linux/solaris/mac on ... Access objects in different schemas.
Low overhead-all functionality required by RPYC is a compact binary protocol with no complex settings (HTTP URL mappings for domain name servers, etc.)
Security-a competency-based security model
Integrated Tls/ssl, SSH and inetd.
# # #Problems resolved in this article:
When using RPYC, if you print on the host (host) side, it is printed only in the host. How can I have the host print directly to the client?
# # #Directly on the code
The first is the client:
Import Sys
Import Rpyc
conn = Rpyc.connect ("localhost", port=18861, config={"Allow_public_attrs": True})
Conn.root.redirect (Sys.stdout)
Conn.root.git_clone ()
Conn.close ()
Service-side:
Import Rpyc
Import OS
Import Sys
Import subprocess
Class MyService (RPYC. Service):
def exposed_redirect (self, stdout):
Sys.stdout = stdout
def exposed_restore (self):
Sys.stdout = sys.__stdout__
def exposed_git_clone (self):
p = subprocess. Popen (["Git", ' Clone ', ' Git@github.com:ejoy/ejoy2d.git ', '--progress '], stdout=subprocess. PIPE, Stderr=subprocess. PIPE)
While True:
nextline = P.stderr.readline ()
if nextline = = ' and P.poll ()!= None:
Break
Print Nextline
if __name__ = = "__main__":
From Rpyc.utils.server import Threadedserver
t = threadedserver (myservice, port = 18861)
T.start ()
After running, you will find that the print nextline command is printed to the client.
Here's another little place to note:
git clone/pull/push This kind of operation, in fact, does not write content to Stdout/stderr (unless sending an error). But if you add a--progress, you'll write the progress to the stderr. In this way, the stderr of our subprocess can be read.