Commit 5e8390d8 authored by sumpfralle's avatar sumpfralle

handle shm access failures gracefully (issue a warning and disable parallel processing)


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1228 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 6b60401e
...@@ -34,27 +34,30 @@ import time ...@@ -34,27 +34,30 @@ import time
import os import os
import sys import sys
log = pycam.Utils.log.get_logger()
try: try:
from multiprocessing.managers import SyncManager from multiprocessing.managers import SyncManager as __SyncManager
except ImportError:
pass
else:
# this class definition needs to be at the top level - for pyinstaller # this class definition needs to be at the top level - for pyinstaller
class TaskManager(SyncManager): class TaskManager(__SyncManager):
@classmethod @classmethod
def _run_server(cls, *args): def _run_server(cls, *args):
# make sure that the server ignores SIGINT (KeyboardInterrupt) # make sure that the server ignores SIGINT (KeyboardInterrupt)
signal.signal(signal.SIGINT, signal.SIG_IGN) signal.signal(signal.SIGINT, signal.SIG_IGN)
# prevent connection errors to trigger exceptions # prevent connection errors to trigger exceptions
try: try:
SyncManager._run_server(*args) __SyncManager._run_server(*args)
except socket.error: except socket.error:
pass pass
except ImportError:
pass
DEFAULT_PORT = 1250 DEFAULT_PORT = 1250
log = pycam.Utils.log.get_logger()
#TODO: create one or two classes for these functions (to get rid of the globals) #TODO: create one or two classes for these functions (to get rid of the globals)
# possible values: # possible values:
...@@ -70,6 +73,7 @@ __manager = None ...@@ -70,6 +73,7 @@ __manager = None
__closing = None __closing = None
__task_source_uuid = None __task_source_uuid = None
__finished_jobs = [] __finished_jobs = []
__issued_warnings = []
def run_in_parallel(*args, **kwargs): def run_in_parallel(*args, **kwargs):
...@@ -88,9 +92,22 @@ def is_multiprocessing_available(): ...@@ -88,9 +92,22 @@ def is_multiprocessing_available():
return False return False
try: try:
import multiprocessing import multiprocessing
# try to initialize a semaphore - this can trigger shm access failures
# (e.g. on Debian Lenny with Python 2.6.6)
multiprocessing.Semaphore()
return True return True
except ImportError: except ImportError:
return False if not "missing_module" in __issued_warnings:
log.info("Python's multiprocessing module is missing: " + \
"disabling parallel processing")
__issued_warnings.append("missing_module")
except OSError:
if not "shm_access_failed" in __issued_warnings:
log.info("Python's multiprocessing module failed to acquire " + \
"read/write access to shared memory (shm) - disabling " + \
"parallel processing")
__issued_warnings.append("shm_access_failed")
return False
def is_multiprocessing_enabled(): def is_multiprocessing_enabled():
return bool(__multiprocessing) return bool(__multiprocessing)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment