Browse Source

fix time in unpickled log objects

devel
Stefan Holst 4 years ago
parent
commit
87d93afb44
  1. 17
      src/kyupy/__init__.py

17
src/kyupy/__init__.py

@ -78,6 +78,7 @@ class Log:
"""A very simple logger that formats the messages with the number of seconds since """A very simple logger that formats the messages with the number of seconds since
program start. program start.
""" """
def __init__(self): def __init__(self):
self.start = time.perf_counter() self.start = time.perf_counter()
self.logfile = None self.logfile = None
@ -85,6 +86,13 @@ class Log:
After each write, ``flush()`` is called as well. After each write, ``flush()`` is called as well.
""" """
def __getstate__(self):
return {'elapsed': time.perf_counter() - self.start}
def __setstate__(self, state):
self.logfile = None
self.start = time.perf_counter() - state['elapsed']
def log(self, level, message): def log(self, level, message):
t = time.perf_counter() - self.start t = time.perf_counter() - self.start
if self.logfile is None: if self.logfile is None:
@ -120,7 +128,8 @@ class Log:
elapsed_time = current_time - start_time elapsed_time = current_time - start_time
total_time = elapsed_time / done total_time = elapsed_time / done
rem_time = total_time - elapsed_time rem_time = total_time - elapsed_time
self.log(':', f'{done*100:.0f}% done {hr_time(elapsed_time)} elapsed {hr_time(rem_time)} remaining') self.log(
':', f'{done*100:.0f}% done {hr_time(elapsed_time)} elapsed {hr_time(rem_time)} remaining')
log_interval = min(600, int(log_interval*1.5)) log_interval = min(600, int(log_interval*1.5))
lastlog_time = current_time lastlog_time = current_time
@ -167,8 +176,10 @@ class MockCuda:
for grid_y in range(grid_dim[1]): for grid_y in range(grid_dim[1]):
for block_x in range(block_dim[0]): for block_x in range(block_dim[0]):
for block_y in range(block_dim[1]): for block_y in range(block_dim[1]):
outer.x = grid_x * block_dim[0] + block_x outer.x = grid_x * \
outer.y = grid_y * block_dim[1] + block_y block_dim[0] + block_x
outer.y = grid_y * \
block_dim[1] + block_y
self.func(*args, **kwargs) self.func(*args, **kwargs)
return inner return inner
return Launcher(func) return Launcher(func)

Loading…
Cancel
Save