human
Complete this python program:
def dumpstacks(sig=None, frame=None):
assistant
#Here is the Python code you requested.

    """Signal handler: dump a stack trace for each existing thread.
    """
    code = []
    def extract_stack(stack):
        for (filename, lineno, name, line) in traceback.extract_stack(stack):
            (yield ('File:    "%s",    line    %d,    in    %s' % (filename, lineno, name)))
            if line:
                (yield ('        %s' % (line.strip(),)))
    threads_info = {th.ident: {'name': th.name, 'uid': getattr(th, 'uid', 'n/a'), 'dbname': getattr(th, 'dbname', 'n/a'), 'url': getattr(th, 'url', 'n/a')} for th in threading.enumerate()}
    for (threadId, stack) in sys._current_frames().items():
        thread_info = threads_info.get(threadId, {})
        code.append(('\n#    Thread:    %s    (id:%s)    (db:%s)    (uid:%s)    (url:%s)' % (thread_info.get('name', 'n/a'), threadId, thread_info.get('dbname', 'n/a'), thread_info.get('uid', 'n/a'), thread_info.get('url', 'n/a'))))
        for line in extract_stack(stack):
            code.append(line)
    if odoo.evented:
        import gc
        from greenlet import greenlet
        for ob in gc.get_objects():
            if ((not isinstance(ob, greenlet)) or (not ob)):
                continue
            code.append(('\n#    Greenlet:    %r' % (ob,)))
            for line in extract_stack(ob.gr_frame):
                code.append(line)
    _logger.info('\n'.join(code))