Skip to content

Instantly share code, notes, and snippets.

View tongyx361's full-sized avatar

Shawn/Yuxuan Tong tongyx361

View GitHub Profile
@tongyx361
tongyx361 / print-debug.py
Last active December 1, 2023 12:48
Python print for debugging
# >>> debug
def print_debug(name, obj):
print(f"[DEBUG] {name}: ({type(obj).__name__})({obj})", end="\n---\n")
print_debug("test", [])
# <<< debug
@tongyx361
tongyx361 / init-logging.py
Last active November 30, 2023 13:30
Initialize Logging in Python
def init_logging(
log_path=None,
format="[%(levelname)s] [%(asctime)s.%(msecs)d] [pid %(process)d] [%(pathname)s:%(lineno)d:%(funcName)s]\n%(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
level=logging.INFO,
force=True,
):
if force:
logging.shutdown()
@tongyx361
tongyx361 / gpu-monitor-with-executor-and-email.py
Created August 1, 2023 17:10
Python script that monitors GPU usage on a machine and executes jobs when GPUs are available.
"""
GPU Monitor with Email and Execution
This script monitors the usage of GPUs on a system and, when there are enough free GPUs, execute a specified function.
The function run a bash script by default but could be any other executable code.
This script uses the GPUtil library to monitor GPU usage.
Preparation:
1. `pip install GPUtil`
2. define your own `func` if needed