def test_run_job_memory_leak(): class FooBar(object): pass def func(): foo = FooBar() # noqa: F841 raise Exception('dummy') fake_job = Mock(Job, func=func, args=(), kwargs={}, misfire_grace_time=1) with patch('logging.getLogger'): for _ in range(5): run_job(fake_job, 'foo', [datetime.now(UTC)], __name__) foos = [x for x in gc.get_objects() if type(x) is FooBar] assert len(foos) == 0
def _do_submit_job(self, job, run_times): try: events = run_job(job, job._jobstore_alias, run_times, self._logger.name) except: self._run_job_error(job.id, *sys.exc_info()[1:]) else: self._run_job_success(job.id, events)