MCPcopy
hub / github.com/huggingface/transformers / printflock

Function printflock

scripts/distributed/torch-distributed-gpu-test.py:53–60  ·  view source on GitHub ↗

solves multi-process interleaved print problem

(*msgs)

Source from the content-addressed store, hash-verified

51
52
53def printflock(*msgs):
54 """solves multi-process interleaved print problem"""
55 with open(__file__, "r") as fh:
56 fcntl.flock(fh, fcntl.LOCK_EX)
57 try:
58 print(*msgs)
59 finally:
60 fcntl.flock(fh, fcntl.LOCK_UN)
61
62
63local_rank = int(os.environ["LOCAL_RANK"])

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected