REDIRECT command line output when using RPYC in Python

Source: Internet
Author: User
Tags git clone in python


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.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.