Commit 92334c61 authored by sumpfralle's avatar sumpfralle

fixes for remote processing on Windows: use the external network interface for local servers

git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@968 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 4030b765
...@@ -26,6 +26,7 @@ __all__ = ["iterators", "polynomials", "ProgressCounter", "threading", ...@@ -26,6 +26,7 @@ __all__ = ["iterators", "polynomials", "ProgressCounter", "threading",
import sys import sys
import os import os
import socket
# this is imported below on demand # this is imported below on demand
#import win32com #import win32com
#import win32api #import win32api
...@@ -54,6 +55,39 @@ def get_platform(): ...@@ -54,6 +55,39 @@ def get_platform():
return PLATFORM_UNKNOWN return PLATFORM_UNKNOWN
def get_all_ips():
""" try to get all IPs of this machine
The resulting list of IPs contains non-local IPs first, followed by
local IPs (starting with "127....").
"""
result = []
def get_ips_of_name(name):
try:
ips = socket.gethostbyname_ex(name)
if len(ips) == 3:
return ips[2]
except socket.gaiaerror:
return []
result.extend(get_ips_of_name(socket.gethostname()))
result.extend(get_ips_of_name("localhost"))
filtered_result = []
for ip in result:
if not ip in filtered_result:
filtered_result.append(ip)
def sort_ip_by_relevance(ip1, ip2):
if ip1.startswith("127."):
return 1
if ip2.startswith("127."):
return -1
else:
return cmp(ip1, ip2)
# non-local IPs first
filtered_result.sort(cmp=sort_ip_by_relevance)
print filtered_result
return filtered_result
def get_external_program_location(key): def get_external_program_location(key):
extensions = ["", ".exe"] extensions = ["", ".exe"]
potential_names = ["%s%s" % (key, ext) for ext in extensions] potential_names = ["%s%s" % (key, ext) for ext in extensions]
......
...@@ -21,6 +21,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -21,6 +21,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
""" """
import pycam.Utils.log import pycam.Utils.log
import pycam.Utils
# multiprocessing is imported later # multiprocessing is imported later
#import multiprocessing #import multiprocessing
import Queue import Queue
...@@ -128,6 +129,26 @@ def get_task_statistics(): ...@@ -128,6 +129,26 @@ def get_task_statistics():
result["cache"] = __manager.cache().length() result["cache"] = __manager.cache().length()
return result return result
class ManagerInfo(object):
""" this separate class allows proper pickling for "multiprocesssing"
"""
def __init__(self, tasks, results, stats, cache, pending):
self.tasks_queue = tasks
self.results_queue = results
self.statistics = stats
self.cache = cache
self.pending_tasks = pending
def get_tasks_queue(self):
return self.tasks_queue
def get_results_queue(self):
return self.results_queue
def get_statistics(self):
return self.statistics
def get_cache(self):
return self.cache
def get_pending_tasks(self):
return self.pending_tasks
def init_threading(number_of_processes=None, enable_server=False, remote=None, def init_threading(number_of_processes=None, enable_server=False, remote=None,
run_server=False, server_credentials="", local_port=DEFAULT_PORT): run_server=False, server_credentials="", local_port=DEFAULT_PORT):
global __multiprocessing, __num_of_processes, __manager, __closing, __task_source_uuid global __multiprocessing, __num_of_processes, __manager, __closing, __task_source_uuid
...@@ -222,7 +243,18 @@ def init_threading(number_of_processes=None, enable_server=False, remote=None, ...@@ -222,7 +243,18 @@ def init_threading(number_of_processes=None, enable_server=False, remote=None,
worker_uuid_list = [str(uuid.uuid1()) for index in range(__num_of_processes)] worker_uuid_list = [str(uuid.uuid1()) for index in range(__num_of_processes)]
__task_source_uuid = str(uuid.uuid1()) __task_source_uuid = str(uuid.uuid1())
if remote is None: if remote is None:
address = ('localhost', local_port) # try to guess an appropriate interface for binding
if pycam.Utils.get_platform() == pycam.Utils.PLATFORM_WINDOWS:
# Windows does not support a wildcard interface listener
all_ips = pycam.Utils.get_all_ips()
if all_ips:
address = (all_ips[0], local_port)
log.info("Binding to local interface with IP %s" % str(all_ips[0]))
else:
return "Failed to find any local IP"
else:
# empty hostname -> wildcard interface (does not work with windows)
address = ('', local_port)
else: else:
if ":" in remote: if ":" in remote:
host, port = remote.split(":", 1) host, port = remote.split(":", 1)
...@@ -242,11 +274,12 @@ def init_threading(number_of_processes=None, enable_server=False, remote=None, ...@@ -242,11 +274,12 @@ def init_threading(number_of_processes=None, enable_server=False, remote=None,
statistics = ProcessStatistics() statistics = ProcessStatistics()
cache = ProcessDataCache() cache = ProcessDataCache()
pending_tasks = PendingTasks() pending_tasks = PendingTasks()
TaskManager.register("tasks", callable=lambda: tasks_queue) info = ManagerInfo(tasks_queue, results_queue, statistics, cache, pending_tasks)
TaskManager.register("results", callable=lambda: results_queue) TaskManager.register("tasks", callable=info.get_tasks_queue)
TaskManager.register("statistics", callable=lambda: statistics) TaskManager.register("results", callable=info.get_results_queue)
TaskManager.register("cache", callable=lambda: cache) TaskManager.register("statistics", callable=info.get_statistics)
TaskManager.register("pending_tasks", callable=lambda: pending_tasks) TaskManager.register("cache", callable=info.get_cache)
TaskManager.register("pending_tasks", callable=info.get_pending_tasks)
else: else:
TaskManager.register("tasks") TaskManager.register("tasks")
TaskManager.register("results") TaskManager.register("results")
...@@ -290,7 +323,7 @@ def cleanup(): ...@@ -290,7 +323,7 @@ def cleanup():
log.debug("Shutting down process handler") log.debug("Shutting down process handler")
try: try:
__closing.set(True) __closing.set(True)
except EOFError: except IOError, EOFError:
log.debug("Connection to manager lost during cleanup") log.debug("Connection to manager lost during cleanup")
# Only managers that were started via ".start()" implement a "shutdown". # Only managers that were started via ".start()" implement a "shutdown".
# Managers started via ".connect" may skip this. # Managers started via ".connect" may skip this.
...@@ -345,8 +378,11 @@ def _spawn_daemon(manager, number_of_processes, worker_uuid_list): ...@@ -345,8 +378,11 @@ def _spawn_daemon(manager, number_of_processes, worker_uuid_list):
except KeyboardInterrupt: except KeyboardInterrupt:
log.info("Spawner daemon killed by keyboard interrupt") log.info("Spawner daemon killed by keyboard interrupt")
# set the "closing" flag and just exit # set the "closing" flag and just exit
__closing.set(True) try:
except EOFError: __closing.set(True)
except IOError, EOFError:
pass
except IOError, EOFError:
# the connection was closed # the connection was closed
log.info("Spawner daemon lost connection to server") log.info("Spawner daemon lost connection to server")
......
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