Skip to content

Commit

Permalink
Update dhcp.py
Browse files Browse the repository at this point in the history
Fix issue where DelayWorker would week the server to close if the queue is empty.
  • Loading branch information
vitormhenrique authored Dec 28, 2018
1 parent 4888142 commit 3d1eb63
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions server/dhcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,17 @@ def __init__(self):

def _delay_response_thread(self):
while not self.closed:
p = self.queue.get()
if self.closed:
break
t, func, args, kw = p
now = time.time()
if now < t:
time.sleep(0.01)
self.queue.put(p)
else:
func(*args, **kw)
if not self.queue.empty():
p = self.queue.get()
t, func, args, kw = p
now = time.time()
if now < t:
time.sleep(0.01)
self.queue.put(p)
else:
func(*args, **kw)

def do_after(self, seconds, func, args = (), kw = {}):
self.queue.put((time.time() + seconds, func, args, kw))
Expand Down

0 comments on commit 3d1eb63

Please sign in to comment.