Skip to content

Commit

Permalink
Merge pull request #10 from greggzj/master
Browse files Browse the repository at this point in the history
propose another way for DelayWorker close issue
  • Loading branch information
niccokunzmann authored Jun 16, 2019
2 parents 58e9b01 + 32ba283 commit a05f114
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions server/dhcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,17 @@ def _delay_response_thread(self):
while not self.closed:
if self.closed:
break
if not self.queue.empty():
p = self.queue.get()
try:
p = self.queue.get(timeout=1)
t, func, args, kw = p
now = time.time()
if now < t:
time.sleep(0.01)
self.queue.put(p)
else:
func(*args, **kw)
except queue.Empty:
continue

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

0 comments on commit a05f114

Please sign in to comment.