multiprocessing and accessing server's stdout

Adam Tauno Williams awilliam at whitemice.org
Fri May 28 08:17:44 EDT 2010


On Thu, 2010-05-27 at 08:36 -0700, Tim Arnold wrote:
> On May 26, 4:52 pm, Adam Tauno Williams <awill... at whitemice.org>
> wrote:
> > On Wed, 2010-05-26 at 11:47 -0700, Tim Arnold wrote:
> > > Hi,
> > > I'm using multiprocessing's BaseManager to create a server on one
> > > machine and a client on another. The client fires a request and the
> > > server does some work, the result of which ends up on a shared file
> > > system that both the client and server can see.
> > > However, I need the client machine to see the stdout of the process
> > > running on the server. Not sure this is doable--I've been unable to
> > > google anything useful on this one.
> >
> > Nope, it isn't.  Don't use stdout, use an IPC mechanism to communicate
> > between the client and the server if you need feedback.
> Thanks for that info, it saves me some time. This is a new area for me
> though: do you redirect stdout on the server to a socket and have the
> client listen and somehow pipe the sockets contents to the client
> stdout?

No, I close stdin, stderr, and stdout on the server processes and attach
them to /dev/null.  Just don't use stdout.

> Interestingly, the RPYc package manages it--that is, the client gets
> the stdout of the server process, so I'll dig into that code to get an
> idea. In the meantime, are there any recipes or other docs that would
> be helpful? I've been googling but without much luck.

Closing stdout and attaching it to any other file descriptor is pretty
simple.

sys.stdout = open('/dev/null', 'w')

You should be able to point it any any file-like object.  But, again,
why?

If you have the data in the process why send it to stdout and redirect
it.  Why not just send the data to the client directly?
-- 
Adam Tauno Williams <awilliam at whitemice.org> LPIC-1, Novell CLA
<http://www.whitemiceconsulting.com>
OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba




More information about the Python-list mailing list