Skip to content

Commit

Permalink
Add _safe_write_to_file back to pypiper for Pepatac backwards compat
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldcampbelljr committed Jul 14, 2023
1 parent 2ef7a6a commit 539dd1b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [0.13.1] -- 2023-07-14
### Fixed
- added _safe_write_to_file back into pypiper for Pepatac backwards compatibility

## [0.13.0] -- 2023-06-29
### Added

Expand Down
35 changes: 35 additions & 0 deletions pypiper/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1691,6 +1691,41 @@ def report_object(
self.info(r)
return reported_result

def _safe_write_to_file(self, file, message):
"""
Writes a string to a file safely (with file locks).
"""
warnings.warn(
"This function may be removed in future release. "
"The recommended way to report pipeline results is using PipelineManager.pipestat.report().",
category=DeprecationWarning,
)
target = file
lock_name = make_lock_name(target, self.outfolder)
lock_file = self._make_lock_path(lock_name)

while True:
if os.path.isfile(lock_file):
self._wait_for_lock(lock_file)
else:
try:
self.locks.append(lock_file)
self._create_file_racefree(lock_file)
except OSError as e:
if e.errno == errno.EEXIST:
self.warning("Lock file created after test! Looping again.")
continue # Go back to start

# Proceed with file writing
with open(file, "a") as myfile:
myfile.write(message + "\n")

os.remove(lock_file)
self.locks.remove(lock_file)

# If you make it to the end of the while loop, you're done
break

def _report_command(self, cmd, procs=None):
"""
Writes a command to both stdout and to the commands log file
Expand Down

0 comments on commit 539dd1b

Please sign in to comment.