[chimera-dev] Direct standard output to Reply Log
gregc at cgl.ucsf.edu
Tue Dec 2 16:08:53 PST 2014
This is normal consequence of running a program and redirecting its
output. When the subprocess outputs to a terminal, the output is
line-buffered, but if the output is not going to a terminal, then the
output accumulates (8K bytes usually, but varies depending on your
operating system) before being printed. The solution is to alter the
subprocess to turn off output buffering (or turn on line-buffering). In
C, the function to call is setbuf(stdout, NULL). If the subprocess is
written in Python, then give the -u argument to Python (or set the
PYTHONUNBUFFERED environment variable).
On 12/02/2014 02:23 PM, user wrote:
> I am new to write Chimera code. Right now I am trying to run another program as a subprocess within Chimera.
> While I was trying to redirect the standard output from the subprocess to “Reply Log”, the results could be shown only after the subprocess finished but not simultaneously. I was wandering how should I redirect the output to “Reply Log” while the subprocess program is running.
> Right now I have something like this:
> def show(sub):
> for line in sub.stdout:
> subproc = SM.Popen(cmd, stdin=None, stdout = SM.PIPE, stderr=SM.PIPE)
> subprog = SM.monitor(‘prog’, subproc, title=‘run’, task=task, afterCB=show(subproc))
> If I run this block within the IDLE, then the result printed while it is running (seems still a bit delayed).
> Where should I change?
> Thank you in advance.
> Chimera-dev mailing list
> Chimera-dev at cgl.ucsf.edu
More information about the Chimera-dev