Skip to content

Instantly share code, notes, and snippets.

@vadimkantorov
Created February 22, 2023 12:36
Show Gist options
  • Save vadimkantorov/4afd3f2c86092887045c0fd406e24130 to your computer and use it in GitHub Desktop.
Save vadimkantorov/4afd3f2c86092887045c0fd406e24130 to your computer and use it in GitHub Desktop.
Print in multi-threaded/multi-process env
# from https://github.com/stas00/toolbox/blob/master/pytorch/all_reduce_bench.py
def printflock(*msgs):
""" print """
with open(__file__, "r") as fh:
fcntl.flock(fh, fcntl.LOCK_EX)
try:
print(*msgs)
finally:
fcntl.flock(fh, fcntl.LOCK_UN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment