Stop __del__ raising on objects whose construction failed - #93
Merged
Conversation
birkholz-cubert
force-pushed
the
feature/handle-lifecycle-and-capture
branch
2 times, most recently
from
August 19, 2026 16:37
92cea29 to
3d44353
Compare
Every SDK handle owner sets self._handle to None before the call that would fill it in, so a constructor that raises leaves a half-built object behind. __del__ then handed that None to the SWIG free function, which raised TypeError. Python does not propagate out of __del__, it prints, so the symptom was an unrelated looking traceback surfacing after an error the caller had already handled. Ten sites, guarded uniformly; seven of the eight testable classes were affected. Two ride along, both in AcquisitionContext.capture. The to_internal path passed a Python 0 where SWIG wants an int32_t*, so it raised before reaching the SDK and the internal queue documented at cuvis.h:1886 was unreachable from Python; SWIG marshals None to NULL. The parameter is also renamed off its misspelling. No alias is kept for to_interal: the next release is a major version, and a rename is not a feature removal, so callers get a plain TypeError rather than a deprecation cycle for a typo.
birkholz-cubert
force-pushed
the
feature/handle-lifecycle-and-capture
branch
from
August 19, 2026 17:15
3d44353 to
cb79622
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
__del__implementations against a handle that was never assigned. Seven of the eight testable handle owners previously raisedTypeErrorout of garbage collection after any failed construction.AcquisitionContext.capture(to_internal=True)now reaches the SDK. It passed a Python0where SWIG wants anint32_t*, so it raised before the call and the internal queue was unreachable from Python.to_interalparameter toto_internal, with no alias for the old spelling.tests/test_handle_lifecycle.pyplus three capture tests.Why
self._handle = Nonebefore the call that fills it in, so a constructor that raises leaves a half-built object for the collector. Python prints rather than propagates exceptions from__del__, so the symptom was an unrelated looking traceback appearing after an error the caller had already handled.cuvis.h:1886documents a null result handle as the way to queue a capture internally, so the intent was right and only the marshalling was wrong. SWIG will not coerce a Python int to a null pointer, but it does marshalNone.The queue switch, verified in both directions
cuvis.h:1887names two consumers of the internal queue,cuvis_acq_cont_get_next_measurementand the worker. Both were checked, with the queue proved empty beforehand so nothing else can be mistaken for the capture under test.to_internal=TruereturnsNone, and the measurement arrives at the direct consumer and at aWorkerwithset_acquisition_context. The result is processed to a(275, 290, 51)cube to prove it is a usable measurement and not a handle the SDK never filled in. The queue is empty again afterwards, so exactly one measurement was produced.to_internal=Falsereturns anAsyncMesuand puts nothing in the queue. The async result is collected first, so the capture is known to have happened; neither consumer then sees anything. This is the half of the ALL-5828 report that does not reproduce, now pinned by a regression test rather than changed.Pitfalls
to_interal=by keyword; they getTypeError: capture() got an unexpected keyword argument 'to_interal'. Positional callers are unaffected. This wants to land in the major release it assumes.Verification
developand pass 8/8 here.developafter Require Python 3.10 and use the annotations it provides #94; no legacyOptional/Unionannotations remain, confirmed withruff check --select UP006,UP007,UP035,UP045.ruff check,ruff format --checkandscripts/check_changelog.pyclean.