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:
002ee93
)
python: Added an abort timeout for the freethread handler.
author
Fredrik Tolf
<fredrik@dolda2000.com>
Sun, 5 Jan 2014 10:57:53 +0000
(11:57 +0100)
committer
Fredrik Tolf
<fredrik@dolda2000.com>
Sun, 5 Jan 2014 10:57:53 +0000
(11:57 +0100)
python3/ashd/serve.py
patch
|
blob
|
blame
|
history
diff --git
a/python3/ashd/serve.py
b/python3/ashd/serve.py
index
6111ec6
..
74ccd92
100644
(file)
--- a/
python3/ashd/serve.py
+++ b/
python3/ashd/serve.py
@@
-86,24
+86,36
@@
class handler(object):
return {}
class freethread(handler):
return {}
class freethread(handler):
- def __init__(self, *, max=None, **kw):
+ def __init__(self, *, max=None,
timeout=None,
**kw):
super().__init__(**kw)
self.current = set()
self.lk = threading.Lock()
self.tcond = threading.Condition(self.lk)
self.max = max
super().__init__(**kw)
self.current = set()
self.lk = threading.Lock()
self.tcond = threading.Condition(self.lk)
self.max = max
+ self.timeout = timeout
@classmethod
@classmethod
- def parseargs(cls, *, max=None, **args):
+ def parseargs(cls, *, max=None,
abort=None,
**args):
ret = super().parseargs(**args)
if max:
ret["max"] = int(max)
ret = super().parseargs(**args)
if max:
ret["max"] = int(max)
+ if abort:
+ ret["timeout"] = int(abort)
return ret
def handle(self, req):
with self.lk:
return ret
def handle(self, req):
with self.lk:
- while self.max is not None and len(self.current) >= self.max:
- self.tcond.wait()
+ if self.max is not None:
+ if self.timeout is not None:
+ now = start = time.time()
+ while len(self.current) >= self.max:
+ self.tcond.wait(start + self.timeout - now)
+ now = time.time()
+ if now - start > self.timeout:
+ os.abort()
+ else:
+ while len(self.current) >= self.max:
+ self.tcond.wait()
th = reqthread(target=self.run, args=[req])
th.start()
while th.is_alive() and th not in self.current:
th = reqthread(target=self.run, args=[req])
th.start()
while th.is_alive() and th not in self.current: