-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QWatson doesn't save its state correctly when stopping the current activity. #52
Comments
This bug is caused because the In QWatson, the Therefore, if when starting QWatson, the When stopping the current activity, the When restarting QWatson, the So I think that def save(self):
"""
Save the state in the appropriate files. Create them if necessary.
"""
try:
if not os.path.isdir(self._dir):
os.makedirs(self._dir)
if self._current is not None and self._old_state != self._current:
if self.is_started:
current = {
'project': self.current['project'],
'start': self._format_date(self.current['start']),
'tags': self.current['tags'],
'message': self.current.get('message'),
}
else:
current = {}
safe_save(self.state_file, make_json_writer(lambda: current))
# self._old_state = current
if self._frames is not None and self._frames.changed:
safe_save(self.frames_file,
make_json_writer(self.frames.dump))
if self._config_changed:
safe_save(self.config_file, self.config.write)
if self._last_sync is not None:
safe_save(self.last_sync_file,
make_json_writer(self._format_date, self.last_sync))
except OSError as e:
raise WatsonError(
"Impossible to write {}: {}".format(e.filename, e)
) |
Here is an example to reproduce the problem: import os.path as osp
import os
from watson.watson import Watson
watson = Watson()
# We remove the state file if it exists:
if osp.exists(watson.state_file):
os.remove(watson.state_file)
print('Watson is started =', watson.is_started)
print(watson._old_state, watson._current, end='\n\n')
# When starting Watson, the content of the state file is updated to
# that of Watson._current:
print('Starting Watson.')
watson.start('test')
print("Saving 'sate' file =", watson._old_state != watson._current)
print(watson._old_state, watson._current)
watson.save()
print(watson._load_json_file(watson.state_file), end='\n\n')
# When stopping, the content of the state file is not updated because
# both Watson._old_state and Watson._current equal {}:
print('Stoping Watson.')
watson.stop()
print("Saving 'sate' file =", watson._old_state != watson._current)
print(watson._old_state, watson._current)
watson.save()
print(watson._load_json_file(watson.state_file), end='\n\n')
# So when we re-initialized Watson, the Watson._current is initialized from the
# content of the state file. Therefore Watson.is_started return True, but it should return False:
print('Reinitializing Watson.')
watson = Watson()
print('Watson is started =', watson.is_started)
print(watson._old_state, watson._current) This results in :
|
Reported this issue upstream in jazzband/Watson#213 |
QWatson version 0.3.0
watson.save
is triggered).QWatson indicates that it was not closed correctly :
The text was updated successfully, but these errors were encountered: