Skip to content

Commit

Permalink
Don't need cpu_cores.sh anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
ibc committed Nov 23, 2023
1 parent 640edb5 commit 1a3914b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
4 changes: 4 additions & 0 deletions TODO_INVOKE.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ In summary:
```

- "Code QL Analyze (cpp)" CI task fails because "Command failed: invoke -r worker" (as expected): https://github.com/versatica/mediasoup/actions/runs/6973590508/job/18977838894?pr=1239

- Once we have `invoke` working, let's remove the no longer used `cpu_cores.sh` script.

- And of course, remove `Makefile`.
26 changes: 21 additions & 5 deletions worker/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import os;
import inspect;
import shutil;
import subprocess;
import re;
from invoke import task;


Expand All @@ -25,9 +23,11 @@
MEDIASOUP_INSTALL_DIR = os.getenv('MEDIASOUP_INSTALL_DIR') or f'{MEDIASOUP_OUT_DIR}/{MEDIASOUP_BUILDTYPE}';
BUILD_DIR = os.getenv('BUILD_DIR') or f'{MEDIASOUP_INSTALL_DIR}/build';
PIP_DIR = f'{MEDIASOUP_OUT_DIR}/pip';
NUM_CORES = re.findall(
r'\b\d+\b', subprocess.check_output(f'{WORKER_DIR}/scripts/cpu_cores.sh', text=True)
)[0];
# If available (only on some *nix systems), os.sched_getaffinity(0) gets set of
# CPUs the calling thread is restricted to. Instead, os.cpu_count() returns the
# total number of CPUs in a system (it doesn't take into account how many of them
# the calling thread can use).
NUM_CORES = len(os.sched_getaffinity(0)) if hasattr(os, 'sched_getaffinity') else os.cpu_count();
PYTHON = os.getenv('PYTHON') or sys.executable;
MESON = os.getenv('MESON') or f'{PIP_DIR}/bin/meson';
MESON_VERSION = os.getenv('MESON_VERSION') or '1.2.1';
Expand Down Expand Up @@ -69,6 +69,22 @@
os.environ['PYTHONPATH'] = f'{PIP_DIR}:{PYTHONPATH}';


# Utils.

def get_num_cpus():
# If available (only on some *nix systems), os.sched_getaffinity(0) gets
# accurate set of CPUs the calling thread is restricted to.
#
if hasattr(os, 'sched_getaffinity'):
return len(os.sched_getaffinity(0));
# Instead, os.cpu_count() returns the count of the total CPUs in a system
# (it doesn't take into account how many of them the calling thread can use).
else:
return os.cpu_info();


# Tasks.

@task
def meson_ninja(ctx):
"""
Expand Down

0 comments on commit 1a3914b

Please sign in to comment.