File: parallel.py

package info (click to toggle)
w3af 1.0-rc3svn3489-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 59,908 kB
  • ctags: 16,916
  • sloc: python: 136,990; xml: 63,472; sh: 153; ruby: 94; makefile: 40; asm: 35; jsp: 32; perl: 18; php: 5
file content (34 lines) | stat: -rw-r--r-- 923 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- coding: utf-8 -*-
# Copyright © 2007-2008 Stockholm TreeAligner Project
# Author: Torsten Marek <shlomme@gmx.net>
# Licensed under the GNU GPLv2
"""Support module for using the `multiprocessing` module."""

try:
    import processing as multiprocessing
    HAS_PROCESSING = True
except ImportError:
    try:
        import multiprocessing
        HAS_PROCESSING = True
    except ImportError:
        HAS_PROCESSING = False    

__all__ = ["use_parallel_processing"]

if HAS_PROCESSING:
    CPU_COUNT = multiprocessing.cpuCount()
else:
    CPU_COUNT = 1
    multiprocessing = None


def use_parallel_processing():
    """Returns `True` if the query evaluator can run parallelized, `False` otherwise.
    
    For the parallelized version, two conditions have to be fulfilled:
     * the `multiprocessing` module is present
     * the system has more than one CPU
    """
    return HAS_PROCESSING and CPU_COUNT > 1