Skip to content

Commit

Permalink
fix: fixed cpu affinity error on platforms with no support
Browse files Browse the repository at this point in the history
  • Loading branch information
ShyAssassin committed Feb 13, 2024
1 parent 879c9f1 commit c7cb083
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions TrackingBackend/app/utils/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ def _mainloop(self) -> None:
self._last_time = current_time

def set_affinity(self) -> None:
cpu_list = mask_to_cpu_list(self.base_config.affinity_mask)
if cpu_list != []:
self.logger.info(f"affinity={cpu_list} for process `{self.name}`")
psutil.Process().cpu_affinity(cpu_list)
# The MacOS kernel does not export the CPU affinity API to user space
if callable(getattr(psutil.Process(), "cpu_affinity", None)):
cpu_list = mask_to_cpu_list(self.base_config.affinity_mask)
if cpu_list != []:
self.logger.info(f"affinity={cpu_list} for process `{self.name}`")
psutil.Process().cpu_affinity(cpu_list) # type: ignore
else:
self.logger.warning(f"cpu_affinity not supported for process `{self.name}`")

def on_config_modified(self, old_config: EyeTrackConfig) -> None:
self.logger.debug(f"Config updated for process `{self.name}`")
Expand Down

0 comments on commit c7cb083

Please sign in to comment.