Skip to content

MeasurementService: Use a context manager to simplify ctrl-C handling#110

Merged
bkeryan merged 2 commits intomainfrom
users/bkeryan/handle-keyboard-interrupt
Oct 27, 2022
Merged

MeasurementService: Use a context manager to simplify ctrl-C handling#110
bkeryan merged 2 commits intomainfrom
users/bkeryan/handle-keyboard-interrupt

Conversation

@bkeryan
Copy link
Copy Markdown
Collaborator

@bkeryan bkeryan commented Oct 26, 2022

What does this Pull Request accomplish?

Make MeasurementService implement the context manager protocol so that clients can use with measurement_service.host_service(): to clean up automatically.

Remove Win32-specific ctrl-C handling. A with-statement does the right thing when Python raises KeyboardInterrupt.

Why should this Pull Request be merged?

This partially fixes #38 by removing Win32-specific cleanup code.

What testing has been done?

Manually tested sample_measurement:

  • Successfully register service and press enter
  • Successfully register service and press ctrl-C
  • Fail to register service -> no unexpected errors
  • Unmodified examples still work when you press enter, but they no longer clean up when you press ctrl-C.

@bkeryan bkeryan merged commit 8fd691e into main Oct 27, 2022
@bkeryan bkeryan deleted the users/bkeryan/handle-keyboard-interrupt branch October 27, 2022 22:58
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

Successfully merging this pull request may close these issues.

Need to handle un-registration of running service when service is killed abruptly.(Independent of OS architecture )

3 participants