MCPcopy Create free account
hub / github.com/brmmm3/fastthreadpool / as_completed

Method as_completed

fastthreadpool/fastthreadpool.py:515–565  ·  view source on GitHub ↗
(self, wait=None, cnt_max=0)

Source from the content-addressed store, hash-verified

513
514 #c def as_completed(self, wait=None, int cnt_max=0):
515 def as_completed(self, wait=None, cnt_max=0): #p
516 # wait:
517 # True=Wait until all jobs are done
518 # False=Read all results then return immediately
519 # int or float value=Read all results and wait for further results until timeout
520 # timeout=current time at function call + value
521 # cnt_max:
522 # Maximum number of results to read. 0=No limit.
523 #c cdef float to
524 #c cdef object pyto
525 #c cdef bint do_sleep
526 #c cdef int cnt
527 if self._thr_done is not None:
528 raise PoolCallback("Using done_callback!")
529 if self._thr_failed is not None:
530 raise PoolCallback("Using failed_callback!")
531 if wait is not False and isinstance(wait, (int, float)):
532 pyto = _time() + wait
533 to = pyto
534 else:
535 to = pyto = 0.0
536 done = self._done
537 failed = self._failed
538 done_popleft = done.popleft
539 failed_popleft = failed.popleft
540 cnt = 0
541 while self._busy_cnt or self._jobs or done or failed:
542 do_sleep = True
543 while done:
544 yield done_popleft()
545 if self._done_cnt.value > 0:
546 self._done_cnt.acquire(False)
547 if self._done_max > 0:
548 #c pythread.PyThread_release_lock(self._done_max_lock)
549 self._done_max_lock.release() #p
550 if cnt_max > 0:
551 cnt += 1
552 if cnt >= cnt_max:
553 return
554 do_sleep = False
555 while failed:
556 yield failed_popleft()
557 if cnt_max > 0:
558 cnt += 1
559 if cnt >= cnt_max:
560 return
561 do_sleep = False
562 if wait is False or ((to > 0.0) and (_time() > pyto)):
563 return
564 if do_sleep:
565 sleep(0.01)
566
567 #c def _map_child(self, fn, itr, done_callback, bint unpack_args):
568 def _map_child(self, fn, itr, done_callback, unpack_args): #p

Callers

nothing calls this directly

Calls 3

PoolCallbackClass · 0.85
acquireMethod · 0.80
releaseMethod · 0.80

Tested by

no test coverage detected