You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From my understanding, the Watson class is instantiated every time a command is called from the CLI, so that the state of the private attributes of Watson._current and Watson._old_state are reinitialized to None after each command.
The problem occurs when using the same instance of Watson to start and stop a task in an event loop or a script. Because the Watson._old_state is never reinitialized to None between commands, its value is never updated. This prevents the update of the sate file in the save method. Below I present a MWE that illustrates this :
importos.pathasospimportosfromwatson.watsonimportWatsonwatson=Watson()
# We remove the state file if it exists:ifosp.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)
Thanks for the report @jnsebgosselin ❤️ I didn't know about your qwatson project, it looks awesome! Can you propose a PR to review for your suggestion?
From my understanding, the
Watson
class is instantiated every time a command is called from the CLI, so that the state of the private attributes ofWatson._current
andWatson._old_state
are reinitialized toNone
after each command.The problem occurs when using the same instance of
Watson
tostart
andstop
a task in an event loop or a script. Because theWatson._old_state
is never reinitialized toNone
between commands, its value is never updated. This prevents the update of thesate
file in the save method. Below I present a MWE that illustrates this :This results in :
Maybe a solution would be to update the value of
Watson._old_state
every time thestate
file is saved in thesave
method here, something like:The text was updated successfully, but these errors were encountered: