From 44e5941cfc125651b25fd1b55df89cfbe871462e Mon Sep 17 00:00:00 2001 From: timurhai Date: Wed, 14 Jul 2021 16:02:54 +0300 Subject: [PATCH] PDG: workItemResultServerAddr() return IP:port, not localhostname:port On farm artist machine can be not reachable by name. References: #514. --- plugins/houdini/pdg/types/afanasyscheduler.py | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/plugins/houdini/pdg/types/afanasyscheduler.py b/plugins/houdini/pdg/types/afanasyscheduler.py index ded6b3fff..901e72550 100644 --- a/plugins/houdini/pdg/types/afanasyscheduler.py +++ b/plugins/houdini/pdg/types/afanasyscheduler.py @@ -1,6 +1,11 @@ +""" +To reload scheduler type: +import pdg; pdg.TypeRegistry.types().registeredType(pdg.registeredType.Scheduler, "afanasyscheduler").reload() +""" import json import logging import os +import socket import sys import traceback @@ -16,7 +21,6 @@ logging.basicConfig(level = logging.DEBUG) logger = logging.getLogger(__name__) - class AfanasyScheduler(CallbackServerMixin, PyScheduler): """ Scheduler implementation that interfaces with a Afanasy farm instance. @@ -44,6 +48,7 @@ def _initData(self): self.job_id = None self.job_block_name_id = {} self.job_tasks_id_name = {} + self._local_addr = self._getLocalAddr() def _constructJob(self): @@ -109,6 +114,29 @@ def _deleteJob(self): self._initData() + def _getLocalAddr(self): + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + try: + # doesn't even have to be reachable + s.connect(('10.255.255.255', 1)) + addr = s.getsockname()[0] + except Exception: + addr = socket.gethostbyname(socket.gethostname()) + finally: + s.close() + """ Solution from: + https://stackoverflow.com/questions/166506/finding-local-ip-addresses-using-pythons-stdlib?page=1&tab=votes#tab-top + """ + print(addr) + return addr + + def workItemResultServerAddr(self): + # By default it uses local host name. + # On farm better to use direct IP address. + addr, port = self._workItemResultServerAddr.split(':') + addr = ':'.join([self._local_addr, port]) + return addr + def applicationBin(self, i_app, i_work_item): """ [virtual] Returns the path to the given application