Skip to content

Commit

Permalink
compat: darwin: fall back to default poll interval in lieu of sched_r…
Browse files Browse the repository at this point in the history
…r_get_interval

resolves #13
  • Loading branch information
jesteria committed Feb 1, 2023
1 parent 838a942 commit f5a2d19
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/fate/conf/types/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import jinja2
from descriptors import classproperty

from fate.util.compat.cpu import cpu_count
from fate.util.compat.os import cpu_count
from fate.util.format import Dumper, SLoader
from fate.util.iteration import storeresult
from fate.util.sentinel import Undefined
Expand Down
5 changes: 3 additions & 2 deletions src/fate/sched/tiered_tenancy.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import collections
import itertools
import operator
import os
import time

from fate.util.compat.os import get_interval

from .base import TaskProcessPool, TaskScheduler


Expand Down Expand Up @@ -43,7 +44,7 @@ class TieredTenancyScheduler(TaskScheduler):
"""
# Note: optimum time to wait before polling unclear.
# For now, let's just wait a "slice":
poll_frequency = os.sched_rr_get_interval(0)
poll_frequency = get_interval()

def exec_tasks(self, reset=False):
count_completed = 0
Expand Down
13 changes: 13 additions & 0 deletions src/fate/util/compat/cpu.py → src/fate/util/compat/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import os


COMPAT_INTERVAL = 0.02


def cpu_count():
try:
# glibc-only
Expand All @@ -11,3 +14,13 @@ def cpu_count():
return multiprocessing.cpu_count()
else:
return len(sched_getaffinity(0))


def get_interval(default=COMPAT_INTERVAL):
try:
sched_rr_get_interval = os.sched_rr_get_interval
except AttributeError:
# unsupported (e.g. darwin)
return default
else:
return sched_rr_get_interval(0)

0 comments on commit f5a2d19

Please sign in to comment.