Dolda2000 GitWeb
/
ashd.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
ab3275e
)
python3: Make pooled threads start exit when wait-pool is large for some time.
author
Fredrik Tolf
<fredrik@dolda2000.com>
Mon, 4 Apr 2016 00:13:03 +0000
(
02:13
+0200)
committer
Fredrik Tolf
<fredrik@dolda2000.com>
Mon, 4 Apr 2016 00:13:03 +0000
(
02:13
+0200)
python3/ashd/serve.py
patch
|
blob
|
blame
|
history
diff --git
a/python3/ashd/serve.py
b/python3/ashd/serve.py
index
0eddc09
..
7811f66
100644
(file)
--- a/
python3/ashd/serve.py
+++ b/
python3/ashd/serve.py
@@
-204,6
+204,8
@@
class threadpool(handler):
self.ccond = threading.Condition(self.clk)
self.queue = collections.deque()
self.waiting = set()
self.ccond = threading.Condition(self.clk)
self.queue = collections.deque()
self.waiting = set()
+ self.waitlimit = 5
+ self.wlstart = 0.0
self.qlk = threading.Lock()
self.qcond = threading.Condition(self.qlk)
self.max = max
self.qlk = threading.Lock()
self.qcond = threading.Condition(self.qlk)
self.max = max
@@
-275,9
+277,15
@@
class threadpool(handler):
start = now = time.time()
with self.qlk:
while len(self.queue) < 1:
start = now = time.time()
with self.qlk:
while len(self.queue) < 1:
+ if len(self.waiting) >= self.waitlimit and now - self.wlstart >= timeout:
+ return
self.waiting.add(th)
self.waiting.add(th)
- self.qcond.wait(start + timeout - now)
- self.waiting.remove(th)
+ try:
+ if len(self.waiting) == self.waitlimit:
+ self.wlstart = now
+ self.qcond.wait(start + timeout - now)
+ finally:
+ self.waiting.remove(th)
now = time.time()
if now - start > timeout:
return
now = time.time()
if now - start > timeout:
return
@@
-292,7
+300,7
@@
class threadpool(handler):
def close(self):
while True:
def close(self):
while True:
- with self.lk:
+ with self.
c
lk:
if len(self.current) > 0:
th = next(iter(self.current))
else:
if len(self.current) > 0:
th = next(iter(self.current))
else: