Skip to content

Commit

Permalink
get_stats in supervisor
Browse files Browse the repository at this point in the history
  • Loading branch information
divi255 committed Aug 18, 2019
1 parent 38f46cd commit 7057cc1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
18 changes: 10 additions & 8 deletions _test.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@
@background_worker(interval=0.5)
def myworker(*args, **kwargs):
global c
print('worker is running')
print(args)
print(kwargs)
# print('worker is running')
# print(args)
# print(kwargs)
c += 1
time.sleep(0.1)
print(c)
return False
time.sleep(0.3)
# print(c)
# return False


# task_supervisor.mp_pool.apply_async(myworker)
Expand Down Expand Up @@ -144,7 +144,7 @@ def someworker(**kwargs):
# time.sleep(1)
# task_supervisor.stop(wait=2)
# exit()
# myworker.start(123, x=2)
myworker.start(123, x=2)
myqueuedworker.start()
# myeventworker.start()
# someworker.start()
Expand Down Expand Up @@ -219,7 +219,9 @@ def cb(result):
# myworker.stop(wait=True)
# someworker.stop(wait=True)
# print('worker stopped')
time.sleep(3)
for x in range(0,30):
print(task_supervisor.get_stats())
time.sleep(0.1)
# task_supervisor.block()
# loop.run_forever()
task_supervisor.stop(wait=2)
Expand Down
11 changes: 11 additions & 0 deletions atasker/supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ def _get_active_count(self, tt):
elif tt == TT_MP:
return len(self._active_mps)

def get_stats(self):
result = {}
for p in ['pool_size', 'reserve_normal', 'reserve_high']:
result['thread_' + p] = getattr(self, 'thread_' + p)
if self.mp_pool:
result['mp_' + p] = getattr(self, 'mp_' + p)
with self._lock:
result['threads'] = list(self._active_threads)
result['mps'] = list(self._active_mps)
return result

async def _start_task(self,
tt,
task,
Expand Down

0 comments on commit 7057cc1

Please sign in to comment.