Skip to content

Commit

Permalink
Loggiing of the piped output fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
luav committed Aug 20, 2018
1 parent 3d14fe5 commit 07c0dc2
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions mpepool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down

0 comments on commit 07c0dc2

Please sign in to comment.