Skip to content

Commit

Permalink
added printprogress to loopprocessor
Browse files Browse the repository at this point in the history
  • Loading branch information
ARSadri committed Jan 30, 2024
1 parent d6453e2 commit df0cf24
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
5 changes: 3 additions & 2 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ History
* bug fixed in plt_utils
* plt_imshow added to plt_utils

0.10.10 (2024-01-25)
0.10.10 (2024-01-30)
------------------
* rgb2hsv is added
* plt_imshow supports complex color map and is bug free
* plt_imshow supports complex color map and is bug free
* added printprogress to loopprocessor
14 changes: 12 additions & 2 deletions lognflow/loopprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def _loopprocessor_function(
class loopprocessor():
def __init__(self,
targetFunction, n_cpu = None, test_mode = False, logger = print,
concatenate_outputs = True, verbose = True):
concatenate_outputs = True, verbose = True, n_processes = 0):
self.targetFunction = targetFunction
self.test_mode = test_mode
self.aQ = Queue()
Expand All @@ -33,9 +33,15 @@ def __init__(self,
else:
self.n_cpu = n_cpu
self.verbose = verbose
if(self.verbose):
self.n_processes = n_processes
if self.verbose:
self.logger = logger
self.logger(f'lognflow loopprocessor initialized with {self.n_cpu} CPUs.')
if self.n_processes:
assert self.n_processes > 0
assert self.n_processes == int(self.n_processes)
from .printprogress import printprogress
self.pBar = printprogress(self.n_processes)

self.outputs_is_given = False
self.outputs = []
Expand Down Expand Up @@ -68,6 +74,8 @@ def __call__(self, *args, **kwargs):
ret_result = aQElement[1]
if ((not self.any_error) & aQElement[2]):
self.any_error = True
if self.n_processes:
del self.pBar
self.empty_queue = True
error_ret_procID = ret_procID_range.copy()
self.logger('')
Expand All @@ -78,6 +86,8 @@ def __call__(self, *args, **kwargs):
for ret_procID, result in zip(ret_procID_range, ret_result):
self.Q_procID.append(ret_procID)
self.outputs.append(result)
if self.n_processes:
self.pBar()
elif(self.numBusyCores):
self.logger(f'Number of busy cores: {self.numBusyCores}')

Expand Down
2 changes: 1 addition & 1 deletion tests/test_multiprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def test_loopprocessor():
print('-'*80, '\n', inspect.stack()[0][3], '\n', '-'*80)

N = 16
D = 100000
D = 1000000
data = (100+10*np.random.randn(N,D)).astype('int')
mask = (2*np.random.rand(N,D)).astype('int')

Expand Down

0 comments on commit df0cf24

Please sign in to comment.