Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/qcodes/utils/delaykeyboardinterrupt.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,19 @@

def __enter__(self) -> None:
is_main_thread = threading.current_thread() is threading.main_thread()
is_default_sig_handler = (
signal.getsignal(signal.SIGINT) is signal.default_int_handler
)
if is_default_sig_handler and is_main_thread:
self.old_handler = signal.signal(signal.SIGINT, self.handler)
elif is_default_sig_handler:
if not is_main_thread:
log.debug(
"Not on main thread cannot intercept interrupts", extra=self._context
)
return

handler = signal.getsignal(signal.SIGINT)
try:
is_delayed_sig_handler = handler.__self__.__class__ == DelayedKeyboardInterrupt

Check failure on line 57 in src/qcodes/utils/delaykeyboardinterrupt.py

View workflow job for this annotation

GitHub Actions / pytestmypy (windows-latest, 3.12, false)

"__self__" is not a known attribute of "None" (reportOptionalMemberAccess)

Check failure on line 57 in src/qcodes/utils/delaykeyboardinterrupt.py

View workflow job for this annotation

GitHub Actions / pytestmypy (windows-latest, 3.12, false)

Cannot access attribute "__self__" for class "Handlers"   Attribute "__self__" is unknown (reportAttributeAccessIssue)

Check failure on line 57 in src/qcodes/utils/delaykeyboardinterrupt.py

View workflow job for this annotation

GitHub Actions / pytestmypy (windows-latest, 3.12, false)

Cannot access attribute "__self__" for class "int"   Attribute "__self__" is unknown (reportAttributeAccessIssue)

Check failure on line 57 in src/qcodes/utils/delaykeyboardinterrupt.py

View workflow job for this annotation

GitHub Actions / pytestmypy (windows-latest, 3.12, false)

Cannot access attribute "__self__" for class "(int, FrameType | None) -> Any" (reportFunctionMemberAccess)

Check failure on line 57 in src/qcodes/utils/delaykeyboardinterrupt.py

View workflow job for this annotation

GitHub Actions / pytestmypy (ubuntu-latest, 3.13, false)

"__self__" is not a known attribute of "None" (reportOptionalMemberAccess)

Check failure on line 57 in src/qcodes/utils/delaykeyboardinterrupt.py

View workflow job for this annotation

GitHub Actions / pytestmypy (ubuntu-latest, 3.13, false)

Cannot access attribute "__self__" for class "Handlers"   Attribute "__self__" is unknown (reportAttributeAccessIssue)

Check failure on line 57 in src/qcodes/utils/delaykeyboardinterrupt.py

View workflow job for this annotation

GitHub Actions / pytestmypy (ubuntu-latest, 3.13, false)

Cannot access attribute "__self__" for class "int"   Attribute "__self__" is unknown (reportAttributeAccessIssue)

Check failure on line 57 in src/qcodes/utils/delaykeyboardinterrupt.py

View workflow job for this annotation

GitHub Actions / pytestmypy (ubuntu-latest, 3.13, false)

Cannot access attribute "__self__" for class "(int, FrameType | None) -> Any" (reportFunctionMemberAccess)

Check failure on line 57 in src/qcodes/utils/delaykeyboardinterrupt.py

View workflow job for this annotation

GitHub Actions / pytestmypy (ubuntu-latest, 3.12, false)

"__self__" is not a known attribute of "None" (reportOptionalMemberAccess)

Check failure on line 57 in src/qcodes/utils/delaykeyboardinterrupt.py

View workflow job for this annotation

GitHub Actions / pytestmypy (ubuntu-latest, 3.12, false)

Cannot access attribute "__self__" for class "Handlers"   Attribute "__self__" is unknown (reportAttributeAccessIssue)

Check failure on line 57 in src/qcodes/utils/delaykeyboardinterrupt.py

View workflow job for this annotation

GitHub Actions / pytestmypy (ubuntu-latest, 3.12, false)

Cannot access attribute "__self__" for class "int"   Attribute "__self__" is unknown (reportAttributeAccessIssue)

Check failure on line 57 in src/qcodes/utils/delaykeyboardinterrupt.py

View workflow job for this annotation

GitHub Actions / pytestmypy (ubuntu-latest, 3.12, false)

Cannot access attribute "__self__" for class "(int, FrameType | None) -> Any" (reportFunctionMemberAccess)
except Exception:
is_delayed_sig_handler = False

Check warning on line 59 in src/qcodes/utils/delaykeyboardinterrupt.py

View check run for this annotation

Codecov / codecov/patch

src/qcodes/utils/delaykeyboardinterrupt.py#L58-L59

Added lines #L58 - L59 were not covered by tests
if not is_delayed_sig_handler:
self.old_handler = signal.signal(signal.SIGINT, self.handler)

def handler(self, sig: int, frame: FrameType | None) -> None:
def create_forceful_handler(
Expand Down
Loading