English 中文(简体)
管道分处理
原标题:python pipe subprocess i/o over socket

我知道那里也有类似的问题,但我对这个具体例子感到不安,没有找到一个很好的答案。 I m 试图为达尔建立远程后备服务器, 。 I ve 问:,通过援引分处理的净目录来说明这一点。 开放,但我更喜欢编织袖珍,并尽可能与花.合。 将会移交几个格人,因此,我只能看一看所有投入,然后通过。

问题是,服务器似乎没有阅读数据。

此时此刻,我宣读以下法典:

from socket import socket, AF_INET, SOCK_STREAM
import sys
import SocketServer
import subprocess

class DarHandler(SocketServer.BaseRequestHandler):
    def handle(self):
        print( entering handler )
        data = self.request.recv(1024).strip()
        print( got:   + data)
        if data ==  xform :
            s = socket(AF_INET, SOCK_STREAM)
            s.bind((  ,0))
            myaddr, myport = s.getsockname()
            print( bound new socket to {0}:{1} .format(myaddr, myport))
            self.request.send(str(myport))
            s.listen(1)
            conn, remoteaddr = s.accept()
            print( accepted connection from {0}:{1} .format(*remoteaddr))
            xform_input = conn.makefile( rb ,0)
            proc = subprocess.Popen(
                [ /usr/bin/dar_xform ,  -s ,  10k ,  - ,  archives/sockbackup ,],
                 stdin=xform_input
            )
            return_code = proc.wait()
            print( dar_xform returned {0} .format(return_code))
            conn.close()
            self.request.send(str(return_code))
        else:
            self.request.send( bad request )
        print( send result, exiting handler )

server_address = ( localhost , 18010)
def server():
    server = SocketServer.TCPServer(server_address, DarHandler)
    print( listening )
    server.serve_forever()

def client():
    sock = socket(AF_INET, SOCK_STREAM)
    print( connecting to server )
    sock.connect(( localhost , 18010))
    print( connected, sending request )
    sock.send( xform )
    print( waiting for response )
    port = sock.recv(1024)
    print( got:   + port)
    s = socket(AF_INET, SOCK_STREAM)
    s.connect(( localhost , int(port)))
    print( connected to dar_xform port )
    dar_output = s.makefile( wb ,0)
    return_code = subprocess.call(
          [ /usr/bin/dar ,  -B ,  config/test.dcf ,  -c ,  - ,], 
          stdout=dar_output
    )
    print( dar returned {0} .format(return_code))
    s.close()
    result = sock.recv(1024)
    print( received:   + result)
    sock.close()
    print( socket closed, exiting )

if __name__ == "__main__":
    if sys.argv[1].startswith( serv ):
        server()
    else:
        client()

在我管理客户时,我从服务器方面获得以下产出:

listening
entering handler
got: xform
bound new socket to 0.0.0.0:41658
accepted connection from 127.0.0.1:42440

然后,它就坐在那里。 同时,dar 客户和客户在等待服务器的答复:

connecting to server
connected, sending request
waiting for response
got: 41300
connected to dar_xform port


 --------------------------------------------
 53 inode(s) saved
 with 0 hard link(s) recorded
 0 inode(s) changed at the moment of the backup
 0 inode(s) not saved (no inode/file change)
 0 inode(s) failed to save (filesystem error)
 1 inode(s) ignored (excluded by filters)
 0 inode(s) recorded as deleted from reference backup
 --------------------------------------------
 Total number of inodes considered: 54
 --------------------------------------------
 EA saved for 0 inode(s)
 --------------------------------------------
dar returned 0
最佳回答

It looks like the dar_xform command on the server is failing...

提供通向<代码>dar_xform的指令至subprocess.Popen(......)的全文,并看你是否继续有问题。 你所说的话令人怀疑地看上去像一个<条码>,PATH的问题,特别是因为它在快车上工作。

问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签