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",
import sys
import os
import socket
# this is imported below on demand
#import win32com
#import win32api
......@@ -54,6 +55,39 @@ def get_platform():
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):
extensions = ["", ".exe"]
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/>.
"""
import pycam.Utils.log
import pycam.Utils
# multiprocessing is imported later
#import multiprocessing
import Queue
......@@ -128,6 +129,26 @@ def get_task_statistics():
result["cache"] = __manager.cache().length()
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,
run_server=False, server_credentials="", local_port=DEFAULT_PORT):
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,
worker_uuid_list = [str(uuid.uuid1()) for index in range(__num_of_processes)]
__task_source_uuid = str(uuid.uuid1())
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:
if ":" in remote:
host, port = remote.split(":", 1)
......@@ -242,11 +274,12 @@ def init_threading(number_of_processes=None, enable_server=False, remote=None,
statistics = ProcessStatistics()
cache = ProcessDataCache()
pending_tasks = PendingTasks()
TaskManager.register("tasks", callable=lambda: tasks_queue)
TaskManager.register("results", callable=lambda: results_queue)
TaskManager.register("statistics", callable=lambda: statistics)
TaskManager.register("cache", callable=lambda: cache)
TaskManager.register("pending_tasks", callable=lambda: pending_tasks)
info = ManagerInfo(tasks_queue, results_queue, statistics, cache, pending_tasks)
TaskManager.register("tasks", callable=info.get_tasks_queue)
TaskManager.register("results", callable=info.get_results_queue)
TaskManager.register("statistics", callable=info.get_statistics)
TaskManager.register("cache", callable=info.get_cache)
TaskManager.register("pending_tasks", callable=info.get_pending_tasks)
else:
TaskManager.register("tasks")
TaskManager.register("results")
......@@ -290,7 +323,7 @@ def cleanup():
log.debug("Shutting down process handler")
try:
__closing.set(True)
except EOFError:
except IOError, EOFError:
log.debug("Connection to manager lost during cleanup")
# Only managers that were started via ".start()" implement a "shutdown".
# Managers started via ".connect" may skip this.
......@@ -345,8 +378,11 @@ def _spawn_daemon(manager, number_of_processes, worker_uuid_list):
except KeyboardInterrupt:
log.info("Spawner daemon killed by keyboard interrupt")
# set the "closing" flag and just exit
try:
__closing.set(True)
except EOFError:
except IOError, EOFError:
pass
except IOError, EOFError:
# the connection was closed
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