← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/lazr.jobrunner/traceback-reference-cycle into lp:lazr.jobrunner

 

Colin Watson has proposed merging lp:~cjwatson/lazr.jobrunner/traceback-reference-cycle into lp:lazr.jobrunner.

Commit message:
Avoid traceback reference cycles in JobRunner.runJobHandleError.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/lazr.jobrunner/traceback-reference-cycle/+merge/402749

`sys.exc_info()` called from `ReadWriteResource.__call__` returns a tuple containing the exception's traceback object, which has a reference to the `ReadWriteResource.__call__` frame.  Storing that in a local variable creates a reference cycle.  We could clear that variable in a `finally` block to avoid this, but in this case it's easier just to avoid using a local variable entirely.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/lazr.jobrunner/traceback-reference-cycle into lp:lazr.jobrunner.
=== modified file 'NEWS.txt'
--- NEWS.txt	2020-02-27 16:59:57 +0000
+++ NEWS.txt	2021-05-14 09:22:04 +0000
@@ -4,6 +4,7 @@
 UNRELEASED
 ----------
 * Remove unused unittest2 from tests_require.
+* Avoid traceback reference cycles in ``JobRunner.runJobHandleError``.
 
 0.16
 ----

=== modified file 'src/lazr/jobrunner/jobrunner.py'
--- src/lazr/jobrunner/jobrunner.py	2019-07-04 10:49:10 +0000
+++ src/lazr/jobrunner/jobrunner.py	2021-05-14 09:22:04 +0000
@@ -198,13 +198,11 @@
                         % (self.job_str(job), e))
                     job.notifyUserError(e)
                 except Exception:
-                    info = sys.exc_info()
-                    return self._doOops(job, info)
+                    return self._doOops(job, sys.exc_info())
             except Exception as e:
                 # This only happens if _doOops() fails.
                 self.logger.exception("Failure in _doOops: %s" % e)
-                info = sys.exc_info()
-                report = job.makeOopsReport(self.oops_config, info)
+                report = job.makeOopsReport(self.oops_config, sys.exc_info())
                 self.oops_config.publish(report)
                 return report