Skip to content
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

signal usage in get_raw/get_json incompatible with threading #18

Open
klauer opened this issue Nov 28, 2022 · 1 comment
Open

signal usage in get_raw/get_json incompatible with threading #18

klauer opened this issue Nov 28, 2022 · 1 comment

Comments

@klauer
Copy link
Contributor

klauer commented Nov 28, 2022

The last thing I had on the docket here was to try and toss the archapp calls into a thread, in order to free up the gui while PV's were being added to the archive viewer. I tried a few things, but ended up hitting upon the fact that python's signal only works in the main thread of the main interpreter. 😞

traceback
Traceback (most recent call last):
  File "/cds/home/r/roberttk/devrepos/atef/atef/qt_helpers.py", line 332, in run
    self.return_value = self.func(*self.args, **self.kwargs)
  File "/cds/home/r/roberttk/devrepos/atef/atef/widgets/config/data.py", line 267, in add_sig
    widget.add_signal(pv, dev_attr=dev_attr, update_curves=False)
  File "/cds/home/r/roberttk/devrepos/atef/atef/widgets/archive_viewer.py", line 314, in add_signal
    data = self.get_pv_data_snippet(pv)
  File "/cds/home/r/roberttk/devrepos/atef/atef/widgets/archive_viewer.py", line 348, in get_pv_data_snippet
    data = self.archapp._data.get_raw(pv, prev, today)
  File "/cds/home/r/roberttk/devrepos/archapp/archapp/data.py", line 166, in get_raw
    data = get_json(url)
  File "/cds/home/r/roberttk/devrepos/archapp/archapp/url.py", line 70, in get_json
    signal.signal(signal.SIGALRM, _raise_timeout)
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.5.1/lib/python3.9/signal.py", line 56, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread of the main interpreter

perhaps a deeper rework of archapp could help, but at least for now caching should make this less painful on repeat archive-viewer openings?

Originally posted by @tangkong in pcdshub/atef#132 (comment)

@ZLLentz
Copy link
Member

ZLLentz commented Nov 28, 2022

signal is used here entirely to manage timeouts. There are almost certainly better ways to handle this that can be implemented here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants