pikers / piker

(e2e) foss trading for non-tinas
GNU Affero General Public License v3.0
103 stars 17 forks source link

`RuntimeError`-guard mouse handlers? #351

Open goodboy opened 2 years ago

goodboy commented 2 years ago

problem

As a starter NOTE: this probably has much in common with what https://github.com/goodboy/tractor/pull/165 is trying to solve..

I've seen this crash a few times now that often results in a hang instead of a full crash due to the original error:

/home/goodboy/repos/pyqtgraph/pyqtgraph/GraphicsScene/GraphicsScene.py:345: RuntimeWarning: Error sending hover exit event:
Traceback (most recent call last):
  File "/home/goodboy/repos/piker/310/bin/piker", line 33, in <module>
    sys.exit(load_entry_point('piker', 'console_scripts', 'piker')())
  File "/home/goodboy/repos/piker/310/lib/python3.10/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/home/goodboy/repos/piker/310/lib/python3.10/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/home/goodboy/repos/piker/310/lib/python3.10/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/goodboy/repos/piker/310/lib/python3.10/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/goodboy/repos/piker/310/lib/python3.10/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/goodboy/repos/piker/310/lib/python3.10/site-packages/click/decorators.py", line 38, in new_func
    return f(get_current_context().obj, *args, **kwargs)
  File "/home/goodboy/repos/piker/piker/ui/cli.py", line 162, in chart
    _main(
  File "/home/goodboy/repos/piker/piker/ui/_app.py", line 178, in _main
    run_qtractor(
  File "/home/goodboy/repos/piker/piker/ui/_exec.py", line 188, in run_qtractor
    app.exec_()
  File "/home/goodboy/repos/pyqtgraph/pyqtgraph/widgets/GraphicsView.py", line 357, in mouseMoveEvent
    super().mouseMoveEvent(ev)
  File "/home/goodboy/repos/pyqtgraph/pyqtgraph/GraphicsScene/GraphicsScene.py", line 208, in mouseMoveEvent
    if self.sendDragEvent(ev, init=init):
  File "/home/goodboy/repos/pyqtgraph/pyqtgraph/GraphicsScene/GraphicsScene.py", line 345, in sendDragEvent
    debug.printExc("Error sending hover exit event:")
  --- exception caught here ---
  File "/home/goodboy/repos/pyqtgraph/pyqtgraph/GraphicsScene/GraphicsScene.py", line 343, in sendDragEvent
    self.dragItem.mouseDragEvent(event)
  File "/home/goodboy/repos/piker/piker/ui/_overlay.py", line 396, in maybe_broadcast
    return slot(
  File "/home/goodboy/repos/piker/piker/ui/_interaction.py", line 672, in mouseDragEvent
    self.start_ic()
  File "/home/goodboy/repos/piker/piker/ui/_interaction.py", line 400, in start_ic
    self.chart.pause_all_feeds()
  File "/home/goodboy/repos/piker/piker/ui/_chart.py", line 779, in pause_all_feeds
    self.linked.godwidget._root_n.start_soon(feed.pause)
  File "/home/goodboy/repos/piker/310/lib/python3.10/site-packages/trio/_core/_run.py", line 988, in start_soon
    GLOBAL_RUN_CONTEXT.runner.spawn_impl(async_fn, args, self, name)
  File "/home/goodboy/repos/piker/310/lib/python3.10/site-packages/trio/_core/_run.py", line 1429, in spawn_impl
    raise RuntimeError("Nursery is closed to new arrivals")
RuntimeError: Nursery is closed to new arrivals
  debug.printExc("Error sending hover exit event:")

the source cause for the error is usually something else that made trio's runtime crash. in my most recent case it was this (my guess is this was the issue in #332):

  Traceback (most recent call last):
  File "/home/goodboy/repos/tractor/tractor/_actor.py", line 193, in _invoke
    await chan.send({'return': await coro, 'cid': cid})
  File "/home/goodboy/repos/piker/piker/fsp/_engine.py", line 319, in cascade
    async with (
  File "/home/goodboy/repos/piker/310/lib/python3.10/site-packages/trio/_core/_run.py", line 815, in __aexit__
    raise combined_error_from_nursery
  File "/home/goodboy/repos/piker/piker/fsp/_engine.py", line 212, in fsp_compute
    async for processed in out_stream:
  File "/home/goodboy/repos/piker/piker/fsp/_volume.py", line 292, in flow_rates
    dvlm_shm = dolla_vlm.get_shm(ohlcv)
  File "/home/goodboy/repos/piker/piker/fsp/_api.py", line 138, in get_shm
    shm = attach_shm_array(dst_token)
  File "/home/goodboy/repos/piker/piker/data/_sharedmem.py", line 563, in attach_shm_array
    raise _err
  File "/home/goodboy/repos/piker/piker/data/_sharedmem.py", line 553, in attach_shm_array
    shm = SharedMemory(
  File "/usr/lib/python3.10/multiprocessing/shared_memory.py", line 103, in __init__
    self._fd = _posixshmem.shm_open(
FileNotFoundError: [Errno 2] No such file or directory: '/mes.globex.20220916.ib.fsp.dolla_vlm.chart.2e6008dd-16ce-4b2f-ae47-64120e95b8d5'

no clue, but after hitting ctrl-c after such a traceback i get something like:

  traceback (most recent call last):
  File "/home/goodboy/repos/piker/piker/ui/_exec.py", line 109, in event
    def event(self, event):
  File "/home/goodboy/repos/tractor/tractor/_debug.py", line 723, in shield_sigint
    raise KeyboardInterrupt
KeyboardInterrupt
/home/goodboy/repos/piker/310/lib/python3.10/site-packages/trio/_core/_run.py:2235: RuntimeWarning: Trio guest run got abandoned without properly finishing... weird stuff might happen
  warnings.warn(

at which point further ctrl-cs do nothing..


solutions