Skip to content

Commit

Permalink
Simplify watcher logic around number of threads - Docker detection no…
Browse files Browse the repository at this point in the history
…t working anymore
  • Loading branch information
benoit74 committed Feb 26, 2024
1 parent e7bd0bd commit 2864f40
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions watcher/watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import datetime
import json
import logging
import multiprocessing
import os
import pathlib
import re
Expand Down Expand Up @@ -64,21 +63,6 @@
logging.getLogger(logger_name).setLevel(logging.WARNING)


def is_running_inside_container():
"""whether running inside a Docker container"""
fpath = pathlib.Path("/proc/self/cgroup")
if not fpath.exists():
return False
try:
with open(fpath, "r") as fh:
for line in fh.readlines():
if line.strip().rsplit(":", 1)[-1] != "/":
return True
finally:
pass
return False


def get_version_for(url):
"""casted datetime of the Last-Modified header for an URL"""
with requests.head(url, allow_redirects=True) as resp:
Expand Down Expand Up @@ -559,13 +543,10 @@ def entrypoint():
)
parser.add_argument(
"--threads",
help="How many threads to run to parallelize download/upload? "
"Defaults to 1 inside Docker as we can't guess available CPUs",
help="How many threads to run to parallelize download/upload? Defaults to 1",
dest="nb_threads",
type=int,
default=(
1 if is_running_inside_container() else multiprocessing.cpu_count() - 1 or 1
),
default=1,
)

parser.add_argument(
Expand Down

0 comments on commit 2864f40

Please sign in to comment.