phurwicz / hover

:speedboat: Label data at scale. Fun and precision included.
https://phurwicz.github.io/hover
MIT License
323 stars 19 forks source link

Session not accessible on browser refresh #47

Closed robinsonkwame closed 2 years ago

robinsonkwame commented 2 years ago

I accidentally hit back while labeling and the Bokeh ioloop was unable to retrieve the prior session,

[ioloop.py:760 - _run_callback()] Exception in callback functools.partial(<bound method IOLoop._discard_future_result of <tornado.platform.asyncio.AsyncIOMainLoop object at 0x7f672643b6d0>>, <Task finished name='Task-64563' coro=<ServerSession.with_document_locked() done, defined at /hdd/work/anaconda3/envs/qca/lib/python3.10/site-packages/bokeh/server/session.py:78> exception=UnsetValueError("DataTable(id='1019', ...).view doesn't have a value set")>)
Traceback (most recent call last):
  File "/hdd/work/anaconda3/envs/qca/lib/python3.10/site-packages/hover/utils/bokeh_helper.py", line 116, in load
    layout.children.append(bokeh_model)
  File "/hdd/work/anaconda3/envs/qca/lib/python3.10/site-packages/bokeh/core/property/wrappers.py", line 140, in wrapper
    self._notify_owners(old)
  File "/hdd/work/anaconda3/envs/qca/lib/python3.10/site-packages/bokeh/core/property/wrappers.py", line 169, in _notify_owners
    descriptor._notify_mutated(owner, old, hint=hint)
  File "/hdd/work/anaconda3/envs/qca/lib/python3.10/site-packages/bokeh/core/property/descriptors.py", line 596, in _notify_mutated
    self._set(obj, old, value, hint=hint)
  File "/hdd/work/anaconda3/envs/qca/lib/python3.10/site-packages/bokeh/core/property/descriptors.py", line 559, in _set
    self._trigger(obj, old, value, hint=hint, setter=setter)
  File "/hdd/work/anaconda3/envs/qca/lib/python3.10/site-packages/bokeh/core/property/descriptors.py", line 637, in _trigger
    obj.trigger(self.name, old, value, hint, setter)
  File "/hdd/work/anaconda3/envs/qca/lib/python3.10/site-packages/bokeh/model/model.py", line 564, in trigger
    self.document.models.invalidate()
  File "/hdd/work/anaconda3/envs/qca/lib/python3.10/site-packages/bokeh/document/models.py", line 184, in invalidate
    self.recompute()
  File "/hdd/work/anaconda3/envs/qca/lib/python3.10/site-packages/bokeh/document/models.py", line 204, in recompute
    new_models |= mr.references()
  File "/hdd/work/anaconda3/envs/qca/lib/python3.10/site-packages/bokeh/model/model.py", line 441, in references
    return set(collect_models(self))
  File "/hdd/work/anaconda3/envs/qca/lib/python3.10/site-packages/bokeh/model/util.py", line 159, in collect_models
    return collect_filtered_models(None, *input_values)
  File "/hdd/work/anaconda3/envs/qca/lib/python3.10/site-packages/bokeh/model/util.py", line 139, in collect_filtered_models
    visit_immediate_value_references(obj, queue_one)
  File "/hdd/work/anaconda3/envs/qca/lib/python3.10/site-packages/bokeh/model/util.py", line 205, in visit_immediate_value_references
    child = getattr(value, attr)
  File "/hdd/work/anaconda3/envs/qca/lib/python3.10/site-packages/bokeh/core/property/descriptors.py", line 234, in __get__
    raise UnsetValueError(f"{obj}.{self.name} doesn't have a value set")
bokeh.core.property.descriptors.UnsetValueError: DataTable(id='1019', ...).view doesn't have a value set

so I lost about an hour of labeling work. Fortunately, I exported the dataset minutes before this happened and I hope I can load it as a SupervisiableDataset and start where I left off.

EDIT - I was able to restore with SupervisableTextDataset.from_pandas and making sure that df[SUBSET] was not set to raw.

haochuanwei commented 2 years ago

Restoring a session

This can help locate the session given its id: https://docs.bokeh.org/en/latest/docs/reference/command/subcommands/serve.html#session-id-options

If you are using bokeh.server.Server and need to find your session id: https://docs.bokeh.org/en/latest/docs/reference/server/server.html#bokeh.server.server.BaseServer.get_sessions

Saving work

In my practice it's often a good idea to use something like apscheduler for periodic auto-saves by a callback function like dataset.to_pandas().to_csv().


Actually this could be a good FAQ.

robinsonkwame commented 2 years ago

Good to know. I ended up developing a solution that auto-loaded the last saved export on start up. Thanks for the references.