Skip to content

Commit

Permalink
second problem of #17
Browse files Browse the repository at this point in the history
  • Loading branch information
ideal committed Oct 10, 2020
1 parent 8e8a1ac commit 1f1b14a
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions mirror/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,31 +89,34 @@ def start(self):
}

def sleep(self):
self.append_tasks()
self.write_mmap()

nexttask = self.queue[0]
self.todo = 0
if nexttask:
for taskinfo in self.queue:
if taskinfo.time > nexttask.time:
break
self.todo |= self.TODO.get(taskinfo.tasktype, 0)
# nexttask.time - time.time() is
# the duration we can sleep...
if nexttask:
sleeptime = nexttask.time - time.time()
# if system time is updated by ntpdate or other ways,
# we may get a sleeptime < 0 and thus an "Invalid argument" error,
# so we need to change it to a valid value
sleeptime = 0 if sleeptime < 0 else sleeptime
else:
sleeptime = 1800 # half an hour
log.info("I am going to sleep, next waking up: %s",
time.ctime(time.time() + sleeptime))
self.expect_time = int(time.time()) + sleeptime
self.roused_by_child = False
# SIGCHLD may be coming before into sleep()
# better need something like pselect() + sig_atomic_t
try:
self.append_tasks()
self.write_mmap()

nexttask = self.queue[0]
self.todo = 0
if nexttask:
for taskinfo in self.queue:
if taskinfo.time > nexttask.time:
break
self.todo |= self.TODO.get(taskinfo.tasktype, 0)
# nexttask.time - time.time() is
# the duration we can sleep...
if nexttask:
sleeptime = nexttask.time - time.time()
# if system time is updated by ntpdate or other ways,
# we may get a sleeptime < 0 and thus an "Invalid argument" error,
# so we need to change it to a valid value
sleeptime = 0 if sleeptime < 0 else sleeptime
else:
sleeptime = 1800 # half an hour
log.info("I am going to sleep, next waking up: %s",
time.ctime(time.time() + sleeptime))
self.expect_time = int(time.time()) + sleeptime
self.roused_by_child = False

time.sleep(sleeptime)
except mirror.error.MirrordTaskFinishedFakeError as e:
pass
Expand Down

0 comments on commit 1f1b14a

Please sign in to comment.