当前位置: 首页>>代码示例>>Python>>正文


Python threading.BoundedSemaphore方法代码示例

本文整理汇总了Python中threading.BoundedSemaphore方法的典型用法代码示例。如果您正苦于以下问题:Python threading.BoundedSemaphore方法的具体用法?Python threading.BoundedSemaphore怎么用?Python threading.BoundedSemaphore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在threading的用法示例。


在下文中一共展示了threading.BoundedSemaphore方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import threading [as 别名]
# 或者: from threading import BoundedSemaphore [as 别名]
def __init__(self, args_):
        self._args = args_
        self.write2sql_thread = None
        self.pool_sqlconnections = BoundedSemaphore(value=self._args.sql_max_connection)
        self.userdata = {
            'haveresponse' : False,
            'starttime'    : time.time()
        }
        self.mqttc, ret = self.mqtt_connect(
            host=self._args.mqtt_host,
            port=self._args.mqtt_port,
            username=self._args.mqtt_username,
            password=self._args.mqtt_password,
            keepalive=self._args.mqtt_keepalive,
            cafile=self._args.mqtt_cafile,
            certfile=self._args.mqtt_certfile,
            keyfile=self._args.mqtt_keyfile,
            insecure=self._args.mqtt_insecure,
            userdata=self.userdata
            )
        if ret != ExitCode.OK:
            SignalHandler.exitus(ret, '{}:{} failed - [{}] {}'.format(self._args.mqtt_host, self._args.mqtt_port, ret, mqtt.error_string(ret))) 
开发者ID:curzon01,项目名称:mqtt2sql,代码行数:24,代码来源:mqtt2sql.py

示例2: __init__

# 需要导入模块: import threading [as 别名]
# 或者: from threading import BoundedSemaphore [as 别名]
def __init__(self, *args, stream_timeout=None, max_parallel_processing=1, **kwds):
        """
        :param scheduler: the decorated scheduler
        :param stream_timeout: the default timeout value in seconds used by StreamScheduler.join
        :param max_parallel_processing: the maximum number of parallelized expectation
            processing (defaults to 1)
        """
        queue_size = 1024
        self._attr.stream_scheduler = Namespace()
        self._attr.stream_scheduler.timeout = stream_timeout
        self._attr.stream_scheduler.max_parallel_processing = max_parallel_processing
        self._attr.stream_scheduler.token_count = threading.BoundedSemaphore(
            max_parallel_processing
        )
        self._attr.stream_scheduler.expectation_queue = deque([], queue_size)
        self._attr.stream_scheduler.pending_expectations = set()
        self._attr.stream_scheduler.on_done_condition = threading.Condition() 
开发者ID:Parrot-Developers,项目名称:olympe,代码行数:19,代码来源:expectations.py

示例3: init_caches_and_synchronization

# 需要导入模块: import threading [as 别名]
# 或者: from threading import BoundedSemaphore [as 别名]
def init_caches_and_synchronization(self):
    """Initializes all caches."""
    self._nodes_cache = simple_cache.SimpleCache(
        constants.MAX_CACHED_DATA_AGE_SECONDS,
        constants.CACHE_DATA_CLEANUP_AGE_SECONDS)
    self._pods_cache = simple_cache.SimpleCache(
        constants.MAX_CACHED_DATA_AGE_SECONDS,
        constants.CACHE_DATA_CLEANUP_AGE_SECONDS)
    self._services_cache = simple_cache.SimpleCache(
        constants.MAX_CACHED_DATA_AGE_SECONDS,
        constants.CACHE_DATA_CLEANUP_AGE_SECONDS)
    self._rcontrollers_cache = simple_cache.SimpleCache(
        constants.MAX_CACHED_DATA_AGE_SECONDS,
        constants.CACHE_DATA_CLEANUP_AGE_SECONDS)

    self._bounded_semaphore = threading.BoundedSemaphore(
        constants.MAX_CONCURRENT_COMPUTE_GRAPH) 
开发者ID:google,项目名称:cluster-insight,代码行数:19,代码来源:global_state.py

示例4: test_BoundedSemaphore_limit

# 需要导入模块: import threading [as 别名]
# 或者: from threading import BoundedSemaphore [as 别名]
def test_BoundedSemaphore_limit(self):
        # BoundedSemaphore should raise ValueError if released too often.
        for limit in range(1, 10):
            bs = threading.BoundedSemaphore(limit)
            threads = [threading.Thread(target=bs.acquire)
                       for _ in range(limit)]
            for t in threads:
                t.start()
            for t in threads:
                t.join()
            threads = [threading.Thread(target=bs.release)
                       for _ in range(limit)]
            for t in threads:
                t.start()
            for t in threads:
                t.join()
            self.assertRaises(ValueError, bs.release) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_threading.py

示例5: __init__

# 需要导入模块: import threading [as 别名]
# 或者: from threading import BoundedSemaphore [as 别名]
def __init__(self, queue, num_threads, timeout=0):
        """
        Init thread worker
        :param Queue.Queue queue: simple queue object
        :param int num_threads: threads numbers
        :param int timeout: delay timeout
        """

        super(Worker, self).__init__()
        self.__semaphore = BoundedSemaphore(num_threads)
        self.__event = Event()
        self.__event.set()
        self.__empty = False
        self.__running = True
        self.__queue = queue
        self.__timeout = timeout
        self.counter = 0 
开发者ID:stanislav-web,项目名称:OpenDoor,代码行数:19,代码来源:worker.py

示例6: __init__

# 需要导入模块: import threading [as 别名]
# 或者: from threading import BoundedSemaphore [as 别名]
def __init__(self, file: str, output: str, line_count: int,
                 threads: int = 8, chunk_size: int = 64, quiet: bool = False,
                 verbose: bool = False):
        """
        Cracker constructor
        :param threads: Number of threads to attempt to crack the signature
        :param file: File to (attempt) to crack
        :param output: Output file to write the file to
        :param chunk_size: Number of passwords to attempt per thread
        """
        self.lock = BoundedSemaphore()
        self.pool = ThreadPool(processes=threads)
        self.thread_count = threads

        self.quiet = quiet
        self.verbose = verbose
        self.file = file
        self.output = output
        self.chunk_size = chunk_size
        self.line_count = line_count or 1
        self.has_error = False
        self.iterable = None

        self.attempts = 0
        self.password = None 
开发者ID:Paradoxis,项目名称:StegCracker,代码行数:27,代码来源:cracker.py

示例7: execute_work_plan

# 需要导入模块: import threading [as 别名]
# 或者: from threading import BoundedSemaphore [as 别名]
def execute_work_plan(logger, options, commands_list):
    """ run through commands_list and run various commands in the thread pool """
    logger.info("Executing work plan across a thread pool of size: %s", options.threads)
    utils.GLOBALS["main_thread_lock"] = threading.Lock()
    utils.GLOBALS["thread_pool_lock"] = threading.BoundedSemaphore(options.threads)
    utils.GLOBALS["thread_count"] = len(commands_list)
    logger.debug("Locks created, task list size = %s", utils.GLOBALS["thread_count"])

    # obtain the main thread lock...
    logger.debug("Acquiring main thread lock")
    utils.GLOBALS["main_thread_lock"].acquire()

    for cmd in commands_list:
        logger.debug("waiting for next thread to be available")
        utils.GLOBALS["thread_pool_lock"].acquire()
        logger.debug("thread is available, starting thread")
        threading.Thread(target=commands.run_command, args=(logger, options, cmd, )).start()

    # block on the main thread lock being released...
    logger.debug("Blocking main thread, waiting on commands to finish")
    utils.GLOBALS["main_thread_lock"].acquire()
    logger.debug("Main thread lock released, working on output") 
开发者ID:aws-samples,项目名称:aws-with,代码行数:24,代码来源:workplan.py

示例8: main

# 需要导入模块: import threading [as 别名]
# 或者: from threading import BoundedSemaphore [as 别名]
def main():
    global semaphore, sends

    signal.signal(signal.SIGINT, interrupt_handler)
    args = commandline()
    print(' ( Shell:{shell}, Numbers:{max_request}, Threads:{max_threads}, Retry:{max_retry} )\n'.format(**args.__dict__))

    semaphore = BoundedSemaphore(value=args.max_threads)
    stopwatch_start = time.time()
    for i, payload in enumerate(create_payload(args), 1):
        if attack:
            sends = i
            semaphore.acquire()
            t = Thread(target=crack, args=(i, args, payload))
            t.setDaemon(True)
            t.start()

    for _ in range(args.max_threads):
        semaphore.acquire()

    stopwatch = time.time() - stopwatch_start
    words = args.max_request * sends if sends else pwd_total
    speed = words / stopwatch if stopwatch else 0
    msg = '[Success] Password: {}'.format(pwd) if pwd else '[Failed] No password found'
    print('\n\n{msg}\n[Finish] {words} words in {stopwatch:.3f} seconds. ({speed:.0f} w/s)'.format(**locals())) 
开发者ID:L-codes,项目名称:oneshellcrack,代码行数:27,代码来源:oneshellcrack.py

示例9: setUp

# 需要导入模块: import threading [as 别名]
# 或者: from threading import BoundedSemaphore [as 别名]
def setUp(self):
        """Set up.

        Creates a FirewallEnforcer object with current and expected rules set to
        an empty FirewallRules object.
        """
        super(FirewallEnforcerTest, self).setUp()

        self.expected_rules = fe.FirewallRules(constants.TEST_PROJECT)
        self.current_rules = fe.FirewallRules(constants.TEST_PROJECT)

        self.project_sema = threading.BoundedSemaphore(value=1)

        self.enforcer = fe.FirewallEnforcer(
            constants.TEST_PROJECT, self.gce_api_client, self.expected_rules,
            self.current_rules, self.project_sema, None) 
开发者ID:forseti-security,项目名称:forseti-security,代码行数:18,代码来源:gce_firewall_enforcer_test.py

示例10: __init__

# 需要导入模块: import threading [as 别名]
# 或者: from threading import BoundedSemaphore [as 别名]
def __init__(self,
                 global_configs,  # pylint: disable= unused-argument
                 rule_defs=None,
                 snapshot_timestamp=None):
        """Initialize.

        Args:
            global_configs (dict): Global configurations.
            rule_defs (dict): The parsed dictionary of rules from the YAML
                definition file.
            snapshot_timestamp (str): The snapshot to lookup data.
        """
        super(EnabledApisRuleBook, self).__init__()
        self._rules_sema = threading.BoundedSemaphore(value=1)
        self.resource_rules_map = collections.defaultdict(set)
        if not rule_defs:
            self.rule_defs = {}
        else:
            self.rule_defs = rule_defs
            self.add_rules(rule_defs)
        if snapshot_timestamp:
            self.snapshot_timestamp = snapshot_timestamp 
开发者ID:forseti-security,项目名称:forseti-security,代码行数:24,代码来源:enabled_apis_rules_engine.py

示例11: __init__

# 需要导入模块: import threading [as 别名]
# 或者: from threading import BoundedSemaphore [as 别名]
def __init__(self,
                 # TODO: To remove the unused global-configs here, it will be
                 # necessary to also update the base rules engine.
                 global_configs,  # pylint: disable= unused-argument
                 rule_defs=None,
                 snapshot_timestamp=None):
        """Initialize.

        Args:
            global_configs (dict): Global configurations.
            rule_defs (dict): The parsed dictionary of rules from the YAML
                definition file.
            snapshot_timestamp (str): The snapshot to lookup data.
        """
        super(IamRuleBook, self).__init__()
        self._rules_sema = threading.BoundedSemaphore(value=1)
        self.resource_rules_map = {}
        if not rule_defs:
            self.rule_defs = {}
        else:
            self.rule_defs = rule_defs
            self.add_rules(rule_defs)
        if snapshot_timestamp:
            self.snapshot_timestamp = snapshot_timestamp 
开发者ID:forseti-security,项目名称:forseti-security,代码行数:26,代码来源:iam_rules_engine.py

示例12: __init__

# 需要导入模块: import threading [as 别名]
# 或者: from threading import BoundedSemaphore [as 别名]
def __init__(self, global_configs, rule_defs=None, snapshot_timestamp=None):
        """Initialization.

        Args:
            global_configs (dict): Global configurations.
            rule_defs (list): IAP rule definition dicts
            snapshot_timestamp (int): Snapshot timestamp.
        """
        super(IapRuleBook, self).__init__()
        del global_configs
        self._rules_sema = threading.BoundedSemaphore(value=1)
        self.resource_rules_map = {}
        if not rule_defs:
            self.rule_defs = {}
        else:
            self.rule_defs = rule_defs
            self.add_rules(rule_defs)
        self.snapshot_timestamp = snapshot_timestamp 
开发者ID:forseti-security,项目名称:forseti-security,代码行数:20,代码来源:iap_rules_engine.py

示例13: __init__

# 需要导入模块: import threading [as 别名]
# 或者: from threading import BoundedSemaphore [as 别名]
def __init__(self,
                 global_configs,  # pylint: disable= unused-argument
                 rule_defs=None,
                 snapshot_timestamp=None):
        """Initialize.

        Args:
            global_configs (dict): Global configurations.
            rule_defs (dict): The parsed dictionary of rules from the YAML
                definition file.
            snapshot_timestamp (str): The snapshot to lookup data.
        """
        super(AuditLoggingRuleBook, self).__init__()
        self._rules_sema = threading.BoundedSemaphore(value=1)
        self.resource_rules_map = collections.defaultdict(set)
        if not rule_defs:
            self.rule_defs = {}
        else:
            self.rule_defs = rule_defs
            self.add_rules(rule_defs)
        if snapshot_timestamp:
            self.snapshot_timestamp = snapshot_timestamp 
开发者ID:forseti-security,项目名称:forseti-security,代码行数:24,代码来源:audit_logging_rules_engine.py

示例14: __init__

# 需要导入模块: import threading [as 别名]
# 或者: from threading import BoundedSemaphore [as 别名]
def __init__(self, rule_defs=None):
        """Initialization.

        Args:
            rule_defs (dict): rule definitons
        """
        super(RetentionRuleBook, self).__init__()
        self._rules_sema = threading.BoundedSemaphore(value=1)

        self.resource_rules_map = {
            applies_to: collections.defaultdict(set)
            for applies_to in SUPPORTED_RETENTION_RES_TYPES}
        if not rule_defs:
            self.rule_defs = {}
        else:
            self.rule_defs = rule_defs
            self.add_rules(rule_defs) 
开发者ID:forseti-security,项目名称:forseti-security,代码行数:19,代码来源:retention_rules_engine.py

示例15: test_fallback

# 需要导入模块: import threading [as 别名]
# 或者: from threading import BoundedSemaphore [as 别名]
def test_fallback(self):
        """Without priority specified, it falls back to ThreadPoolExecutor mode."""

        counter = threading.BoundedSemaphore(value=3)

        def worker():
            counter.acquire(blocking=False)

        with PriorityThreadPoolExecutor(max_workers=3) as executor:
            fs = [executor.submit(worker) for _ in range(3)]
            concurrent.futures.wait(fs)

        self.assertFalse(counter.acquire(blocking=False))

        # verify executor shutdown (all threads stopped)
        self.assertFalse(any(t.is_alive() for t in executor._threads)) 
开发者ID:dwavesystems,项目名称:dwave-cloud-client,代码行数:18,代码来源:test_concurrency.py


注:本文中的threading.BoundedSemaphore方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。