Skip to content

Commit

Permalink
optimize checking traceback level
Browse files Browse the repository at this point in the history
  • Loading branch information
keakon committed Mar 28, 2024
1 parent ae26632 commit 4a3b541
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion delayed/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-

__version__ = '1.0.1b1'
__version__ = '1.0.1b2'
19 changes: 16 additions & 3 deletions delayed/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys
import threading
import time
import traceback
import sys
from typing import Union

from .constants import DEFAULT_SLEEP_TIME, MAX_SLEEP_TIME, Status
Expand Down Expand Up @@ -58,12 +58,25 @@ def run(self): # pragma: no cover
except Exception:
logger.exception('Failed to execute task %s.', task._func_path)

need_retry = False
_, _, exc_traceback = sys.exc_info()
if len(traceback.format_tb(exc_traceback)) > 2:
if exc_traceback:
tb_next = exc_traceback.tb_next
if tb_next:
tb_next2 = tb_next.tb_next
if tb_next2:
# invalid call, should not be retried
need_retry = True
# delete tracebacks to avoid memory leak
del tb_next2
del tb_next
del exc_traceback

if need_retry:
self._requeue_task(task)
else:
# invalid call, should not be retried
self._release_task()
self._release_task()
else:
self._release_task()
finally:
Expand Down

0 comments on commit 4a3b541

Please sign in to comment.