Commit 65661798 authored by sumpfralle's avatar sumpfralle

disable multiprocessing for Windows standalone executable

git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@808 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 231e1454
...@@ -23,13 +23,26 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -23,13 +23,26 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
import pycam.Utils.log import pycam.Utils.log
# multiprocessing is imported later # multiprocessing is imported later
#import multiprocessing #import multiprocessing
#from multiprocessing.managers import SyncManager
import Queue import Queue
import signal
import platform import platform
import random import random
import uuid import uuid
import time import time
import os import os
import sys
try:
from multiprocessing.managers import SyncManager
# this class definition needs to be at the top level - for pyinstaller
class TaskManager(SyncManager):
@classmethod
def _run_server(cls, *args):
# make sure that the server ignores SIGINT (KeyboardInterrupt)
signal.signal(signal.SIGINT, signal.SIG_IGN)
SyncManager._run_server(*args)
except ImportError:
pass
DEFAULT_PORT = 1250 DEFAULT_PORT = 1250
...@@ -73,16 +86,48 @@ def get_pool_statistics(): ...@@ -73,16 +86,48 @@ def get_pool_statistics():
def init_threading(number_of_processes=None, enable_server=False, remote=None, run_server=False, def init_threading(number_of_processes=None, enable_server=False, remote=None, run_server=False,
server_credentials=""): server_credentials=""):
global __multiprocessing, __num_of_processes, __manager, __closing, __task_source_uuid global __multiprocessing, __num_of_processes, __manager, __closing, __task_source_uuid
# server mode is disabled for the Windows standalone executable
is_frozen = hasattr(sys, "frozen") and sys.frozen
if is_frozen and (enable_server or run_server):
# server mode is disabled for the Windows pyinstaller standalone
# due to "pickle errors". How to reproduce: run the standalone binary
# with "--enable-server --server-auth-key foo".
server_mode_unavailable = "Server mode is not available for " \
+ "the Windows standalone executable. Please use the " \
+ "installer package instead (if possible)."
if enable_server:
log.warn("Unable to enable server mode with the Windows " \
+ "standalone executable. " \
+ multiprocessing_missing_text)
elif run_server:
log.warn("Unable to run in server-only mode with the Windows " \
+ "standalone executable. " \
+ multiprocessing_missing_text)
else:
# no further warnings required
pass
enable_server = False
run_server = False
# only local -> no server settings allowed # only local -> no server settings allowed
if (not enable_server) and (not run_server): if (not enable_server) and (not run_server):
remote = None remote = None
run_server = None run_server = None
server_credentials = "" server_credentials = ""
try: if is_frozen:
import multiprocessing # Running multiple processes with the Windows standalone executable
mp_is_available = True # causes "WindowsError: invalid handle" error messages. The processes
except ImportError: # can't communicate - thus no results are returned.
# Reproduce with: "--number-of-processes 2"
log.warn("Multiprocessing capabilities are not available for the " \
+ "Windows standable executable. Use the installer package " \
+ "instead (if possible).")
mp_is_available = False mp_is_available = False
else:
try:
import multiprocessing
mp_is_available = True
except ImportError:
mp_is_available = False
if not mp_is_available: if not mp_is_available:
__multiprocessing = False __multiprocessing = False
# Maybe a multiprocessing feature was explicitely requested? # Maybe a multiprocessing feature was explicitely requested?
...@@ -145,14 +190,6 @@ def init_threading(number_of_processes=None, enable_server=False, remote=None, r ...@@ -145,14 +190,6 @@ def init_threading(number_of_processes=None, enable_server=False, remote=None, r
host = remote host = remote
port = DEFAULT_PORT port = DEFAULT_PORT
address = (host, port) address = (host, port)
from multiprocessing.managers import SyncManager
class TaskManager(SyncManager):
@classmethod
def _run_server(cls, *args):
# make sure that the server ignores SIGINT (KeyboardInterrupt)
import signal
signal.signal(signal.SIGINT, signal.SIG_IGN)
SyncManager._run_server(*args)
if remote is None: if remote is None:
tasks_queue = multiprocessing.Queue() tasks_queue = multiprocessing.Queue()
results_queue = multiprocessing.Queue() results_queue = multiprocessing.Queue()
......
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