Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesra committed May 8, 2023
2 parents 2a383a8 + c465c92 commit a2e259a
Show file tree
Hide file tree
Showing 13 changed files with 636 additions and 464 deletions.
284 changes: 179 additions & 105 deletions nornir_pools/__init__.py

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions nornir_pools/ipool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from abc import ABC, abstractmethod
from typing import Callable, Any


class IPool(ABC):

@property
@abstractmethod
def name(self) -> str:
raise NotImplementedError()

@property
@abstractmethod
def num_active_tasks(self) -> int:
raise NotImplementedError()

@abstractmethod
def shutdown(self):
'''
The pool waits for all tasks to complete and frees any resources such as threads in a thread pool
'''
raise NotImplementedError()

@abstractmethod
def wait_completion(self):
'''
Blocks until all tasks have completed
'''
raise NotImplementedError()

@abstractmethod
def add_task(self, name: str, func: Callable[..., Any], *args, **kwargs):
'''
Call a python function on the pool
:param str name: Friendly name of the task. Non-unique
:param function func: Python function pointer to invoke on the pool
:returns: task object
:rtype: task
'''
raise NotImplementedError()

@abstractmethod
def add_process(self, name: str, func: Callable[..., Any], *args, **kwargs):
'''
Invoke a process on the pool. This function creates a task using name and then invokes pythons subprocess
:param str name: Friendly name of the task. Non-unique
:param function func: Process name to invoke using subprocess
:returns: task object
:rtype: task
'''
raise NotImplementedError()
3 changes: 3 additions & 0 deletions nornir_pools/local_machine_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@author: u0490822
'''
import os

import nornir_pools
from . import poolbase
Expand Down Expand Up @@ -51,6 +52,8 @@ def __init__(self, num_threads, is_global = False, *args, **kwargs):
'''
Constructor
'''

num_threads = nornir_pools.ApplyOSThreadLimit(num_threads)

self._num_threads = num_threads

Expand Down
Loading

0 comments on commit a2e259a

Please sign in to comment.