From 07c0dc2680882c3376ec4c4119f57f6c618e4e8a Mon Sep 17 00:00:00 2001 From: luav Date: Mon, 20 Aug 2018 10:34:46 +0200 Subject: [PATCH] Loggiing of the piped output fixed --- mpepool.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mpepool.py b/mpepool.py index df555e6..5db657d 100755 --- a/mpepool.py +++ b/mpepool.py @@ -1138,16 +1138,17 @@ def complete(self, graceful=None): for pout, plog in ((self.pipederr, self.perrlog), (self.pipedout, self.poutlog)): if pout is None or plog is None: continue - # Ensure existance of the parent directory - basedir = os.path.split(plog)[0] - if basedir and not os.path.exists(plog): - os.makedirs(plog) + # Ensure existence of the parent directory for the filename + if isinstance(plog, str): + basedir = os.path.split(plog)[0] + if basedir and not os.path.exists(plog): + os.makedirs(plog) # Append to the file flog = None try: # Add a timestamp if the file is not empty to distinguish logs timestamp = None - flog = open(plog, 'a') + flog = plog if not isinstance(plog, str) else open(plog, 'a') if os.fstat(flog.fileno()).st_size: if timestamp is None: timestamp = time.gmtime() @@ -1160,7 +1161,7 @@ def complete(self, graceful=None): flog = sys.stdout try: print(timeheader(timestamp), file=flog) # Note: prints also newline unlike flog.write() - flog.write(plog) # Write the piped output + flog.write(pout) # Write the piped output except IOError as err: print('ERROR on logging piped data "{}" for "{}": {}' .format(plog, self.name, err), file=sys.stderr)