mlco2/codecarbon

Capture measurements in CSV based on time intervals

開放

#467 建立於 2023年10月30日

 (6 則留言) (0 個反應) (0 位負責人)Python (306 個分叉)auto 404
P3enhancementgood first issue

倉庫指標

星標
 (1,885 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

  • CodeCarbon version: 2.2.2
  • Python version: 3.11.5
  • Operating System: Linux-6.2.0-35-generic-x86_64-with-glibc2.35

Description

I have implemented a method that enables the capture and storage of consumption logs (CSV format) in parallel every second during the execution of my algorithm. Nevertheless, I would be interested in exploring whether there are more efficient alternatives from a technical or academic standpoint to accomplish this process. Below, I am providing the code of my current solution for review and suggestions.

What I Did

from codecarbon import EmissionsTracker
import threading

pthread=1
def fthread():
    while pthread:
        tracker.flush()
        time.sleep(1)

# Creates an instance of a thread and passes the function is executed.
eng_measure = threading.Thread(target=fthread)

# Training 
tracker = EmissionsTracker(project_name="Test",tracking_mode="machine")
tracker.start()
eng_measure.start()
try:
    # code
finally:
    pthread = 0
    eng_measure.join()
    emissions = tracker.stop()

貢獻者指南