Moves .utils.cry to .utils.debug.cry

This commit is contained in:
Ask Solem 2016-06-28 18:45:22 -07:00
Родитель de6cf95522
Коммит b8d5dee7fd
3 изменённых файлов: 37 добавлений и 36 удалений

Просмотреть файл

@ -29,7 +29,7 @@ from celery.exceptions import WorkerShutdown, WorkerTerminate
from celery.five import string, string_t
from celery.loaders.app import AppLoader
from celery.platforms import EX_FAILURE, EX_OK, check_privileges, isatty
from celery.utils import cry
from celery.utils.debug import cry
from celery.utils.imports import qualname
from celery.utils.log import get_logger, in_sighandler, set_in_sighandler
from celery.utils.text import pluralize

Просмотреть файл

@ -10,20 +10,18 @@ from __future__ import absolute_import, print_function, unicode_literals
import numbers
import sys
import traceback
import datetime
from functools import partial
from pprint import pprint
from celery.five import WhateverIO, items, reraise, string_t
from celery.five import items, reraise, string_t
from .functional import memoize # noqa
from .nodenames import worker_direct, nodename, nodesplit
__all__ = ['worker_direct', 'lpmerge',
'is_iterable', 'cry', 'maybe_reraise', 'strtobool',
'is_iterable', 'maybe_reraise', 'strtobool',
'jsonify', 'gen_task_name', 'nodename', 'nodesplit',
'cached_property']
@ -47,35 +45,6 @@ def is_iterable(obj):
return True
def cry(out=None, sepchr='=', seplen=49): # pragma: no cover
"""Return stack-trace of all active threads,
taken from https://gist.github.com/737056."""
import threading
out = WhateverIO() if out is None else out
P = partial(print, file=out)
# get a map of threads by their ID so we can print their names
# during the traceback dump
tmap = {t.ident: t for t in threading.enumerate()}
sep = sepchr * seplen
for tid, frame in items(sys._current_frames()):
thread = tmap.get(tid)
if not thread:
# skip old junk (left-overs from a fork)
continue
P('{0.name}'.format(thread))
P(sep)
traceback.print_stack(frame, file=out)
P(sep)
P('LOCAL VARIABLES')
P(sep)
pprint(frame.f_locals, stream=out)
P('\n')
return out.getvalue()
def maybe_reraise():
"""Re-raise if an exception is currently being handled, or return
otherwise."""

Просмотреть файл

@ -9,11 +9,14 @@
from __future__ import absolute_import, print_function, unicode_literals
import os
import sys
import traceback
from contextlib import contextmanager
from functools import partial
from pprint import pprint
from celery.five import range
from celery.five import WhateverIO, items, range
from celery.platforms import signals
try:
@ -23,7 +26,7 @@ except ImportError:
__all__ = [
'blockdetection', 'sample_mem', 'memdump', 'sample',
'humanbytes', 'mem_rss', 'ps',
'humanbytes', 'mem_rss', 'ps', 'cry',
]
UNITS = (
@ -165,3 +168,32 @@ def _process_memory_info(process):
return process.memory_info()
except AttributeError:
return process.get_memory_info()
def cry(out=None, sepchr='=', seplen=49): # pragma: no cover
"""Return stack-trace of all active threads,
taken from https://gist.github.com/737056."""
import threading
out = WhateverIO() if out is None else out
P = partial(print, file=out)
# get a map of threads by their ID so we can print their names
# during the traceback dump
tmap = {t.ident: t for t in threading.enumerate()}
sep = sepchr * seplen
for tid, frame in items(sys._current_frames()):
thread = tmap.get(tid)
if not thread:
# skip old junk (left-overs from a fork)
continue
P('{0.name}'.format(thread))
P(sep)
traceback.print_stack(frame, file=out)
P(sep)
P('LOCAL VARIABLES')
P(sep)
pprint(frame.f_locals, stream=out)
P('\n')
return out.getvalue()