[GRASS-dev] Python and delayed or missing stderr output
Markus Metz
markus.metz.giswork at gmail.com
Mon Sep 10 00:41:58 PDT 2018
On Sun, Sep 9, 2018 at 9:47 PM Markus Metz <markus.metz.giswork at gmail.com>
wrote:
>
>
>
> On Wed, Sep 5, 2018 at 10:43 AM Markus Neteler <neteler at osgeo.org> wrote:
> >
> > Hi,
> >
> > AFAIK Python buffers (i.e. effectively delays) stderr output which is
> > unhelpful in the GRASS GIS context.
> >
> > Searching for a solution, I found this reference: sys.stdout.flush()
> > e.g.
> >
https://stackoverflow.com/questions/10019456/usage-of-sys-stdout-flush-method
>
> That should be
> sys.stderr.flush()
> right?
>
> Regarding python's multiprocessing, it makes sense that stderr is
suppressed because you would not know which process process produced which
stderr (or stdout) message. There must be a method in python to redirect
stderr and stdout for each process to a unique file, otherwise it would not
be possible to find out why some process failed.
>
> Such a method would need to be implemented in each module usings python's
multiprocessing.
maybe worth a try also with stderr:
https://stackoverflow.com/questions/1501651/log-output-of-multiprocessing-process
i.e. within the function that is the target of multiprocessing.Process
sys.stderr = open(str(os.getpid()) + ".err.log", "w")
and it seems to be a good idea to always sys.stderr.flush() at the end of
the subprocess
Markus M
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20180910/fdef3f55/attachment-0001.html>
More information about the grass-dev
mailing list