From 9f6d48ba4e43b9cadd0b842e6ed1abbfebf759ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Mon, 3 Jan 2011 00:07:01 +0000 Subject: Issue #10798: Reject supporting concurrent.futures if the system has too few POSIX semaphores. --- Lib/concurrent/futures/process.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'Lib/concurrent') diff --git a/Lib/concurrent/futures/process.py b/Lib/concurrent/futures/process.py index f461b7777d..79c60c3d10 100644 --- a/Lib/concurrent/futures/process.py +++ b/Lib/concurrent/futures/process.py @@ -244,6 +244,31 @@ def _queue_manangement_worker(executor_reference, else: work_item.future.set_result(result_item.result) +_system_limits_checked = False +_system_limited = None +def _check_system_limits(): + global _system_limits_checked, _system_limited + if _system_limits_checked: + if _system_limited: + raise NotImplementedError(_system_limited) + _system_limits_checked = True + try: + import os + nsems_max = os.sysconf("SC_SEM_NSEMS_MAX") + except (AttributeError, ValueError): + # sysconf not available or setting not available + return + if nsems_max == -1: + # indetermine limit, assume that limit is determined + # by available memory only + return + if nsems_max >= 256: + # minimum number of semaphores available + # according to POSIX + return + _system_limited = "system provides too few semaphores (%d available, 256 necessary)" % nsems_max + raise NotImplementedError(_system_limited) + class ProcessPoolExecutor(_base.Executor): def __init__(self, max_workers=None): """Initializes a new ProcessPoolExecutor instance. @@ -253,6 +278,7 @@ class ProcessPoolExecutor(_base.Executor): execute the given calls. If None or not given then as many worker processes will be created as the machine has processors. """ + _check_system_limits() _remove_dead_thread_references() if max_workers is None: -- cgit v1.2.1