Commit aa84b719 authored by sumpfralle's avatar sumpfralle

simplified the handling of the different states of parallel/server mode


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@980 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 2b6a3934
...@@ -6292,7 +6292,23 @@ You will need remote workers.&lt;/span&gt;</property> ...@@ -6292,7 +6292,23 @@ You will need remote workers.&lt;/span&gt;</property>
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkFrame" id="frame1"> <object class="GtkLabel" id="ServerModeDisabledLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Server mode is currently not available on your system.
You are probably using the Windows standalone executable.
Instead you could use the PyCAM installer package along with the all-in-one installer of all dependencies.
See the &lt;a href="http://sf.net/apps/mediawiki/pycam/?title=Parallel_Processing_on_different_Platforms"&gt;platform feature matrix&lt;/a&gt; for details.</property>
<property name="use_markup">True</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="ServerModeSettingsFrame">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label_xalign">0</property> <property name="label_xalign">0</property>
<property name="shadow_type">none</property> <property name="shadow_type">none</property>
...@@ -6530,7 +6546,7 @@ The default port is 1250.</property> ...@@ -6530,7 +6546,7 @@ The default port is 1250.</property>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">2</property> <property name="position">3</property>
</packing> </packing>
</child> </child>
</object> </object>
...@@ -6545,16 +6561,8 @@ The default port is 1250.</property> ...@@ -6545,16 +6561,8 @@ The default port is 1250.</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="xalign">0</property> <property name="xalign">0</property>
<property name="label" translatable="yes">Parallel processing is currently not available on your system. <property name="label" translatable="yes">Parallel processing is currently not available on your system.
Please check the following list of possible reasons and fix the problem, if possible. You need to switch to Python v2.6 (or higher) or install the Python module "multiprocessing".
</property>
1) You are using the Windows standalone executable.
Sadly this problem is not too easy to solve. Future releases of PyCAM should remove this limitation.
2) You are using Python 2.5 or below and the package "multiprocessing" is &lt;i&gt;not&lt;/i&gt; installed.
See the &lt;a href="http://sf.net/apps/mediawiki/pycam/?title=Parallel_Processing_on_different_Platforms"&gt;platform feature matrix&lt;/a&gt; for details.
</property>
<property name="use_markup">True</property>
<property name="wrap">True</property> <property name="wrap">True</property>
</object> </object>
<packing> <packing>
......
...@@ -942,12 +942,15 @@ class ProjectGui: ...@@ -942,12 +942,15 @@ class ProjectGui:
# parallel processing settings # parallel processing settings
self.enable_parallel_processes = self.gui.get_object( self.enable_parallel_processes = self.gui.get_object(
"EnableParallelProcesses") "EnableParallelProcesses")
if pycam.Utils.threading.is_parallel_processing_available(): if pycam.Utils.threading.is_multiprocessing_available():
self.gui.get_object("ParallelProcessingDisabledLabel").hide() self.gui.get_object("ParallelProcessingDisabledLabel").hide()
if pycam.Utils.threading.is_server_mode_available():
self.gui.get_object("ServerModeDisabledLabel").hide()
else:
self.gui.get_object("ServerModeSettingsFrame").hide()
else: else:
self.gui.get_object("ParallelProcessSettingsBox").hide() self.gui.get_object("ParallelProcessSettingsBox").hide()
self.enable_parallel_processes.set_sensitive(False) self.gui.get_object("EnableParallelProcesses").hide()
self.enable_parallel_processes.set_active(False)
self.enable_parallel_processes.set_active( self.enable_parallel_processes.set_active(
pycam.Utils.threading.is_multiprocessing_enabled()) pycam.Utils.threading.is_multiprocessing_enabled())
self.enable_parallel_processes.connect("toggled", self.enable_parallel_processes.connect("toggled",
......
...@@ -82,23 +82,31 @@ def run_in_parallel(*args, **kwargs): ...@@ -82,23 +82,31 @@ def run_in_parallel(*args, **kwargs):
def is_pool_available(): def is_pool_available():
return not __manager is None return not __manager is None
def is_multiprocessing_enabled(): def is_multiprocessing_available():
return bool(__multiprocessing)
def is_windows_parallel_processing_available():
# server mode is disabled for the Windows standalone executable
return not (hasattr(sys, "frozen") and sys.frozen)
def is_parallel_processing_available():
if not is_windows_parallel_processing_available():
# Windows -> no parallel processing
return False
try: try:
import multiprocessing import multiprocessing
return True return True
except ImportError: except ImportError:
return False return False
def is_multiprocessing_enabled():
return bool(__multiprocessing)
def is_server_mode_available():
# the following definition should be kept in sync with the wiki:
# http://sf.net/apps/mediawiki/pycam/?title=Parallel_Processing_on_different_Platforms
if pycam.Utils.get_platform() == pycam.Utils.PLATFORM_WINDOWS:
if hasattr(sys, "frozen") and sys.frozen:
return False
else:
return True
else:
try:
import multiprocessing
return True
except ImportError:
return False
def get_number_of_processes(): def get_number_of_processes():
if __num_of_processes is None: if __num_of_processes is None:
return 1 return 1
...@@ -156,8 +164,7 @@ def init_threading(number_of_processes=None, enable_server=False, remote=None, ...@@ -156,8 +164,7 @@ def init_threading(number_of_processes=None, enable_server=False, remote=None,
if __multiprocessing: if __multiprocessing:
# kill the manager and clean everything up for a re-initialization # kill the manager and clean everything up for a re-initialization
cleanup() cleanup()
if (not is_windows_parallel_processing_available()) and \ if (not is_server_mode_available()) and (enable_server or run_server):
(enable_server or run_server):
# server mode is disabled for the Windows pyinstaller standalone # server mode is disabled for the Windows pyinstaller standalone
# due to "pickle errors". How to reproduce: run the standalone binary # due to "pickle errors". How to reproduce: run the standalone binary
# with "--enable-server --server-auth-key foo". # with "--enable-server --server-auth-key foo".
...@@ -181,21 +188,11 @@ def init_threading(number_of_processes=None, enable_server=False, remote=None, ...@@ -181,21 +188,11 @@ def init_threading(number_of_processes=None, enable_server=False, remote=None,
remote = None remote = None
run_server = None run_server = None
server_credentials = "" server_credentials = ""
if not is_windows_parallel_processing_available(): try:
# Running multiple processes with the Windows standalone executable import multiprocessing
# causes "WindowsError: invalid handle" error messages. The processes mp_is_available = True
# can't communicate - thus no results are returned. except ImportError:
# Reproduce with: "--number-of-processes 2"
log.info("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?
......
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