Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stop reusing exception instances #502

Closed
wants to merge 1 commit into from

Conversation

j123b567
Copy link

@j123b567 j123b567 commented May 5, 2020

writeTimeoutError and portNotOpenError ware precreated exception
instances. When rising these exceptions multiple times, stack trace
was appended to existing traces. This leads to two issues

  • no easy to debug real cause of the exception because of wrong
    stack trace
  • memory leak, because stack trace is never cleared. Raising
    portNotOpenError multiple times (understand e.g. one milion
    times, for long running script, it is perfectly possible)
    will cause out of memory

this change just assign specially crafted exception classes to
existing writeTimeoutError and portNotOpenError variables so
they will produce identical message but they are no longer
precreated.

New exceptions are derived from original SerialTimeoutException
and SerialException so existing user code should not break by this
change

closes: #437

writeTimeoutError and portNotOpenError ware precreated exception
instances. When rising these exceptions multiple times, stack trace
was appended to existing traces. This leads to two issues

 - no easy to debug real cause of the exception because of wrong
   stack trace
 - memory leak, because stack trace is never cleared. Raising
   portNotOpenError multiple times (understand e.g. one milion
   times, for long running script, it is perfectly possible)
   will cause out of memory

this change just assign specially crafted exception classes to
existing writeTimeoutError and portNotOpenError variables so
they will produce identical message but they are no longer
precreated.

New exceptions are derived from original SerialTimeoutException
and SerialException so existing user code should not break by this
change

closes: pyserial#437
zsquareplusc added a commit that referenced this pull request Sep 14, 2020
@zsquareplusc
Copy link
Member

Thanks. I preferred to make instances in the raise calls instead of using exception classes. Therefore closing this w/o merging.

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.

Reusing exception instances stacks their tracebacks
2 participants