Skip to content

Commit

Permalink
Guard against set changing size
Browse files Browse the repository at this point in the history
  • Loading branch information
modrzew committed Aug 12, 2016
1 parent fca70cc commit 5b4adb0
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,11 @@ def check(self):
time.sleep(0.5)
# OK, now we're killed
while True:
tasks = sum([not t.done() for t in asyncio.Task.all_tasks(loop)])
try:
tasks = sum(not t.done() for t in asyncio.Task.all_tasks(loop))
except RuntimeError:
# Set changed size during iteration
tasks = '?'
print(
'{} coroutines active'.format(tasks),
end='\r'
Expand Down Expand Up @@ -505,6 +509,11 @@ def get_status_message(self):
dots.append(worker.error_code[0])
else:
dots.append('.' if worker.step % 2 == 0 else ':')
try:
coroutines_count = len(asyncio.Task.all_tasks(self.loop))
except RuntimeError:
# Set changed size during iteration
coroutines_count = '?'
output = [
'PokeMiner\trunning for {}'.format(running_for),
'{len} workers, each visiting ~{avg} points per cycle '
Expand All @@ -517,7 +526,7 @@ def get_status_message(self):
'',
'{} threads and {} coroutines active'.format(
threading.active_count(),
len(asyncio.Task.all_tasks(self.loop)),
coroutines_count,
),
'API latency: min {min:.3f}, max {max:.3f}, avg {avg:.3f}'.format(
**time_stats['api_calls']
Expand Down

0 comments on commit 5b4adb0

Please sign in to comment.