Skip to content

fix: guard against invalid handle (0) in close() - #216

Merged
hmaarrfk merged 1 commit into
colinoflynn:masterfrom
Jah-yee:fix/close-valid-handle
Oct 10, 2026
Merged

hmaarrfk merged 1 commit into
colinoflynn:masterfrom
Jah-yee:fix/close-valid-handle

Conversation

@Jah-yee

@Jah-yee Jah-yee commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes OSError raised in __del__ when no PicoScope device is connected.

Problem: When instantiating ps2000.PS2000() with no device connected, ps2000_open_unit() returns 0. This sets self.handle = 0. In close(), the check if self.handle is not None: evaluates to True (since 0 is not None), so it calls _lowLevelCloseUnit(0) → returns 0 → checkResult(0) → raises OSError in __del__.

Fix: Change if self.handle is not None: to if self.handle: in picobase.py. This treats both None and 0 (and any falsy value) as "not a valid connection", skipping the close call.

Testing

  • Syntax check: python3 -m py_compile picoscope/picobase.py ✅
  • The fix is minimal and localized — it only affects the close guard, no behavior change for valid handles.

Fixes #214

@Jah-yee

Jah-yee commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

Friendly ping — any updates? Happy to address feedback.

@hmaarrfk
hmaarrfk merged commit 7621acf into colinoflynn:master Oct 10, 2026
@hmaarrfk

Copy link
Copy Markdown
Collaborator

thx see latest version

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.

Noise in console from extra call to close_unit when no ps2000 is connected

2 participants