[Jupyter] GPU 사용량 주기적으로 체크하는 코드

2021. 1. 1. 00:40분석 Python/구현 및 자료

728x90
import GPUtil
from threading import Thread
import time

class Monitor(Thread):
    def __init__(self, delay):
        super(Monitor, self).__init__()
        self.stopped = False
        self.delay = delay # Time between calls to GPUtil
        self.start()

    def run(self):
        while not self.stopped:
            GPUtil.showUtilization()
            time.sleep(self.delay)

    def stop(self):
        self.stopped = True
        
monitor = Monitor(10)

멈추는 것은 STOP을 해주면 됨

monitor.stop()
728x90