sandialabs / pyscan

Scientific Measurement Toolbox
https://pyscan.readthedocs.io/en/latest/
MIT License
4 stars 4 forks source link

Implement try/except with keyboard interrupt on demo notebooks? #163

Open rsbrost opened 1 month ago

rsbrost commented 1 month ago

I would consider using the kill switch function I created on the kill-switch branch instead since I think this may have a few advantages, although the tradeoffs must be weighed before settling on a solution.

A potential disadvantage of this could be that if defined as a single key the experiment could be inadvertently stopped by unrelated keyboard use (I haven't tested implementing hotkey combinations, though it seems like a straightforward way of mitigating this).

The advantages of using the kill switch I made are that:

  1. It can be set to any key(s) in an intuitive way.
  2. It appears simpler/more professional and perhaps is more straightforward for those unfamiliar with coding.
  3. It is not dependent on using ctrl+c which is a hotkey that has other potentially unwanted interactions with other programs.
  4. It is convenient and can be easily used with or without plotting to stop experiments at a moment's notice.
  5. It offers clear assurance to experimenters that they can stop their experiment at any time.

Example of an experiment set up and stopped using custom pyscan kill-switch: Image

Both solutions work more or less in the same way, but with different tradeoffs.

rsbrost commented 1 month ago

If not plotting simply use expt.run() instead of try: except keyboardinterrupt: statements. Ensure that this does kill the experiment, and document this better to help users understand how to stop their experiments mid run. This is important for experimenters to feel safe running their experiments and to know that their instruments will be protected.