Created
September 19, 2022 06:59
-
-
Save ayaka14732/85928ed4ff83318f3ab5ac1da263f0fa to your computer and use it in GitHub Desktop.
Check if Google Cloud TPU is in use
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_tpu_in_use() -> bool: | |
import fcntl | |
from fcntl import LOCK_EX, LOCK_NB | |
import posix | |
from posix import O_CREAT, O_RDWR | |
import sys | |
# https://github.com/tensorflow/tensorflow/blob/1a05bad57a2eb870a561daba0255761e0a472d1d/tensorflow/core/tpu/tpu_initializer_helper.cc#L167-L171 | |
fd = posix.open('/tmp/libtpu_lockfile', O_CREAT | O_RDWR, 0o644) | |
try: | |
fcntl.lockf(fd, LOCK_EX | LOCK_NB, 0) | |
except BlockingIOError: | |
return True | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment