- if hasattr(respiter, "close"):
- respiter.close()
- except closed:
- pass
-
-class calllimiter(object):
- def __init__(self, limit):
- self.limit = limit
- self.lock = threading.Condition()
- self.inflight = 0
-
- def waited(self, time):
- if time > 10:
- raise RuntimeError("Waited too long")
-
- def __enter__(self):
- with self.lock:
- start = time.time()
- while self.inflight >= self.limit:
- self.lock.wait(10)
- self.waited(time.time() - start)
- self.inflight += 1
- return self
-
- def __exit__(self, *excinfo):
- with self.lock:
- self.inflight -= 1
- self.lock.notify()
- return False
-
- def call(self, target):
- with self:
- return target()
-
-class abortlimiter(calllimiter):
- def waited(self, time):
- if time > 10:
- os.abort()
+ with self.lk:
+ self.current.remove(th)
+ finally:
+ req.close()
+
+ def close(self):
+ while True:
+ with self.lk:
+ if len(self.current) > 0:
+ th = next(iter(self.current))
+ else:
+ th = None
+ th.join()
+
+names = {"free": freethread}