Skip to content

Commit

Permalink
Add is_kaggle() function (#6285)
Browse files Browse the repository at this point in the history
* Add `is_kaggle()` function

Return True if environment is Kaggle Notebook.

* Remove root loggers only if is_kaggle() == True

* Update general.py
  • Loading branch information
glenn-jocher committed Jan 13, 2022
1 parent 80473a6 commit af00134
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,21 @@
os.environ['NUMEXPR_MAX_THREADS'] = str(NUM_THREADS) # NumExpr max threads


def is_kaggle():
# Is environment a Kaggle Notebook?
try:
assert os.environ.get('PWD') == '/kaggle/working'
assert os.environ.get('KAGGLE_URL_BASE') == 'https://www.kaggle.com'
return True
except AssertionError:
return False


def set_logging(name=None, verbose=True):
# Sets level and returns logger
for h in logging.root.handlers:
logging.root.removeHandler(h) # remove all handlers associated with the root logger object
if is_kaggle():
for h in logging.root.handlers:
logging.root.removeHandler(h) # remove all handlers associated with the root logger object
rank = int(os.getenv('RANK', -1)) # rank in world for Multi-GPU trainings
logging.basicConfig(format="%(message)s", level=logging.INFO if (verbose and rank in (-1, 0)) else logging.WARNING)
return logging.getLogger(name)
Expand Down

0 comments on commit af00134

Please sign in to comment.