Example #1
0
def pool_worker_main(item: WorkItemInput, output: multiprocessing.queues.Queue) -> None:
    try:
        # TODO figure out a more reliable way to suppress this. Redirect output?
        # Ignore ctrl-c in workers to reduce noisy tracebacks (the parent will kill us):
        signal.signal(signal.SIGINT, signal.SIG_IGN)

        if hasattr(os, 'nice'): # analysis should run at a low priority
            os.nice(10)
        set_debug(False)
        filename, options, deadline = item
        stats: Counter[str] = Counter()
        options.stats = stats
        _, module_name = extract_module_from_file(filename)
        try:
            module = load_by_qualname(module_name)
        except NotFound:
            return
        except ErrorDuringImport as e:
            orig, frame = e.args
            message = AnalysisMessage(MessageType.IMPORT_ERR, str(orig), frame.filename, frame.lineno, 0, '')
            output.put((filename, stats, [message]))
            debug(f'Not analyzing "{filename}" because import failed: {e}')
            return
        messages = analyze_any(module, options)
        output.put((filename, stats, messages))
    except BaseException as e:
        raise CrosshairInternal(
            'Worker failed while analyzing ' + filename) from e
Example #2
0
def pool_worker_main(item: WorkItemInput,
                     output: multiprocessing.queues.Queue) -> None:
    try:
        # TODO figure out a more reliable way to suppress this. Redirect output?
        # Ignore ctrl-c in workers to reduce noisy tracebacks (the parent will kill us):
        signal.signal(signal.SIGINT, signal.SIG_IGN)

        if hasattr(os, 'nice'):  # analysis should run at a low priority
            os.nice(10)
        set_debug(False)
        (stats, messages) = pool_worker_process_item(item)
        filename = item[0]
        output.put((filename, stats, messages))
    except BaseException as e:
        raise CrosshairInternal('Worker failed while analyzing ' +
                                filename) from e
Example #3
0
def pool_worker_main(item: WorkItemInput,
                     output: multiprocessing.queues.Queue) -> None:
    try:
        # TODO figure out a more reliable way to suppress this. Redirect output?
        # Ignore ctrl-c in workers to reduce noisy tracebacks (the parent will kill us):
        signal.signal(signal.SIGINT, signal.SIG_IGN)
        if hasattr(os,
                   'nice'):  # <- is this the right way to detect availability?
            os.nice(10)  # analysis should run at a low priority
        set_debug(False)
        member, options, deadline = item
        stats: Counter[str] = Counter()
        options.stats = stats
        try:
            fn = member.get_member()
        except NotFound:
            return
        messages = analyze_any(fn, options)
        output.put((member, stats, messages))
    except BaseException as e:
        raise CrosshairInternal('Worker failed while analyzing ' +
                                member.qual_name) from e