Example #1
0
    def _finalize_manager(process, address, authkey, state, _Client):
        '''
        Shutdown the manager process; will be registered as a finalizer
        '''
        if process.is_alive():
            util.info('sending shutdown message to manager')
            try:
                conn = _Client(address, authkey=authkey)
                try:
                    managers.dispatch(conn, None, 'shutdown')
                finally:
                    conn.close()
            except Exception:
                pass

            process.join(timeout=0.2)
            if process.is_alive():
                util.info('manager still alive')
                if hasattr(process, 'terminate'):
                    util.info('trying to `terminate()` manager process')

                    try:
                        process.terminate()
                        process.join(timeout=0.1)
            # XXX: catch the OS error ... something weird is going on here..
                    except OSError:
                        pass
                    if process.is_alive():
                        util.info('manager still alive after terminate')

        state.value = managers.State.SHUTDOWN
        try:
            del managers.BaseProxy._address_to_local[address]
        except KeyError:
            pass
Example #2
0
    def from_address(cls, address, authkey):
        """
        Return manager given an address.

        address: (ip_addr, port) or string referring to pipe.
            Address to connect to.

        authkey: string
            Authorization key.
        """
        manager = cls(address, authkey)
        conn = connection.Client(address, authkey=authkey)
        try:
            managers.dispatch(conn, None, 'dummy')
        finally:
            conn.close()
        manager._state.value = managers.State.STARTED
        manager._name = 'Host-%s:%s' % manager.address
        manager.shutdown = util.Finalize(manager,
                                         HostManager._finalize_host,
                                         args=(manager._address,
                                               manager._authkey,
                                               manager._name),
                                         exitpriority=-10)
        return manager
Example #3
0
    def _finalize_manager(process, address, authkey, state, _Client):
        '''
        Shutdown the manager process; will be registered as a finalizer
        '''
        if process.is_alive():
            util.info('sending shutdown message to manager')
            try:
                conn = _Client(address, authkey=authkey)
                try:
                    managers.dispatch(conn, None, 'shutdown')
                finally:
                    conn.close()
            except Exception:
                pass

            process.join(timeout=0.2)
            if process.is_alive():
                util.info('manager still alive')
                if hasattr(process, 'terminate'):
                    util.info('trying to `terminate()` manager process')

                    try:
                        process.terminate()
                        process.join(timeout=0.1)
            # XXX: catch the OS error ... something weird is going on here..
                    except OSError:
                        pass
                    if process.is_alive():
                        util.info('manager still alive after terminate')

        state.value = managers.State.SHUTDOWN
        try:
            del managers.BaseProxy._address_to_local[address]
        except KeyError:
            pass
Example #4
0
 def _finalize_manager(process, address, authkey, state, conns, _Client):
     """ Shutdown the manager process; will be registered as a
     finalizer."""
     if process.is_alive():
         util.info("Sending shutdown message to manager.")
         try:
             conn = _Client(fqaddr(address), authkey=authkey)
             try:
                 dispatch(conn, None, "shutdown")
             finally:
                 conn.close()
         except Exception:
             pass
         for conn in conns:
             conn.close()
         process.join(timeout=0.2)
         if process.is_alive():
             util.info("Manager still alive.")
             if hasattr(process, "terminate"):
                 util.info("Trying to `terminate()` manager process.")
                 process.terminate()
                 process.join(timeout=0.1)
                 if process.is_alive():
                     util.info("Manager still alive after terminate.")
     state.value = State.SHUTDOWN
     try:
         del BaseProxy._address_to_local[fqaddr(address)]
     except KeyError:
         pass
Example #5
0
 def connect(self):
     '''
     Connect manager object to the server process
     '''
     Listener, Client = listener_client[self._serializer]
     self._conn = Client(self._address, authkey=self._authkey)
     dispatch(self._conn, None, 'dummy')
     self._state.value = State.STARTED
Example #6
0
 def SharedMemory(self, size):
     """Returns a new SharedMemory instance with the specified size in
     bytes, to be tracked by the manager."""
     with self._Client(self._address, authkey=self._authkey) as conn:
         sms = shared_memory.SharedMemory(None, create=True, size=size)
         try:
             dispatch(conn, None, 'track_segment', (sms.name,))
         except BaseException as e:
             sms.unlink()
             raise e
     return sms
Example #7
0
 def ShareableList(self, sequence):
     """Returns a new ShareableList instance populated with the values
     from the input sequence, to be tracked by the manager."""
     with self._Client(self._address, authkey=self._authkey) as conn:
         sl = shared_memory.ShareableList(sequence)
         try:
             dispatch(conn, None, 'track_segment', (sl.shm.name,))
         except BaseException as e:
             sl.shm.unlink()
             raise e
     return sl
Example #8
0
 def temp(self, *args, **kwds):
     logger.debug("calling self._create(%s,%s)", args, kwds)
     token, exp = self._create(typeid, *args, **kwds)
     proxy = proxytype(token,
                       self._serializer,
                       manager=self,
                       authkey=self._authkey,
                       exposed=exp)
     conn = self._Client(token.address, authkey=self._authkey)
     dispatch(conn, None, 'decref', (token.id, ))
     return proxy
Example #9
0
 def SharedMemory(self, name: str = None, size: int = None):
     assert name is not None or size is not None
     with self._Client(self._address, authkey=self._authkey) as conn:
         if name is not None:
             shm = SharedMemory(name=name)
             self.client_shms[name] = shm
         else:
             shm = SharedMemory(None, create=True, size=size)
             try:
                 dispatch(conn, None, 'track_segment', (shm.name, ))
             except BaseException as e:
                 shm.unlink()
                 raise e
     return shm
Example #10
0
 def _finalize_host(address, authkey, fcleanup, rcleanup):
     """ Sends a shutdown message and cleans up tunnels. """
     mgr_ok = OpenMDAO_Proxy.manager_is_alive(address)
     if mgr_ok:
         conn = connection.Client(address, authkey=authkey)
         try:
             managers.dispatch(conn, None, 'shutdown')
         except EOFError:
             pass
         finally:
             conn.close()
     if fcleanup is not None:
         fcleanup[0](*fcleanup[1:], **dict(keep_log=not mgr_ok))
     if rcleanup is not None:
         rcleanup[0](*rcleanup[1:], **dict(keep_log=not mgr_ok))
 def _finalize_host(address, authkey, fcleanup, rcleanup):
     """ Sends a shutdown message and cleans up tunnels. """
     mgr_ok = OpenMDAO_Proxy.manager_is_alive(address)
     if mgr_ok:
         conn = connection.Client(address, authkey=authkey)
         try:
             managers.dispatch(conn, None, 'shutdown')
         except EOFError:
             pass
         finally:
             conn.close()
     if fcleanup is not None:
         fcleanup[0](*fcleanup[1:], **dict(keep_log=not mgr_ok))
     if rcleanup is not None:
         rcleanup[0](*rcleanup[1:], **dict(keep_log=not mgr_ok))
Example #12
0
 def _finalize_host(address, authkey, name):
     """ Sends a shutdown message. """
     conn = connection.Client(address, authkey=authkey)
     try:
         return managers.dispatch(conn, None, 'shutdown')
     finally:
         conn.close()
Example #13
0
def AsyncAutoProxy(token,
                   serializer,
                   manager=None,
                   authkey=None,
                   exposed=None,
                   incref=True):
    """Return an auto-proxy for `token`."""
    _Client = listener_client[serializer][1]

    if exposed is None:
        conn = _Client(token.address, authkey=authkey)
        try:
            exposed = dispatch(conn, None, 'get_methods', (token, ))
        finally:
            conn.close()

    if authkey is None and manager is not None:
        authkey = manager._authkey
    if authkey is None:
        authkey = process.current_process().authkey

    ProxyType = MakeAsyncProxyType('AutoProxy[%s]' % token.typeid, exposed)
    proxy = ProxyType(token,
                      serializer,
                      manager=manager,
                      authkey=authkey,
                      incref=incref)
    proxy._isauto = True
    return proxy
 def _finalize_host(address, authkey, name):
     """ Sends a shutdown message. """
     conn = connection.Client(address, authkey=authkey)
     try:
         return managers.dispatch(conn, None, 'shutdown')
     finally:
         conn.close()
Example #15
0
def mpm_AutoProxy(token,
                  serializer,
                  manager=None,
                  authkey=None,
                  exposed=None,
                  incref=True,
                  manager_owned=False):
    '''
    Return an auto-proxy for `token`
    '''
    _Client = mpm.listener_client[serializer][1]

    if exposed is None:
        conn = _Client(token.address, authkey=authkey)
        try:
            exposed = mpm.dispatch(conn, None, 'get_methods', (token, ))
        finally:
            conn.close()

    if authkey is None and manager is not None:
        authkey = manager._authkey
    if authkey is None:
        authkey = mpm.process.current_process().authkey

    ProxyType = mpm.MakeProxyType('AutoProxy[%s]' % token.typeid, exposed)
    proxy = ProxyType(token,
                      serializer,
                      manager=manager,
                      authkey=authkey,
                      incref=incref,
                      manager_owned=manager_owned)
    proxy._isauto = True
    return proxy
Example #16
0
    def from_address(cls, address, authkey, host):
        """
        Return manager given an address.

        address: (ip_addr, port) or string referring to pipe.
            Address to connect to.

        authkey: string
            Authorization key.

        host: :class:`Host`
            Host we're managing.
        """
        if host.tunnel_outgoing:
            _LOGGER.debug('Client setting up tunnel for %s:%s', host.hostname,
                          address[1])
            address, cleanup = setup_tunnel(host.hostname,
                                            address[1],
                                            identity=host.identity_filename)
        else:
            cleanup = None

        manager = cls(address, authkey)
        _LOGGER.debug('Client connecting to server at %s' % (address, ))
        conn = connection.Client(address, authkey=authkey)
        try:
            managers.dispatch(conn, None, 'dummy')
        finally:
            conn.close()
        manager._state.value = managers.State.STARTED
        manager._name = 'Host-%s:%s' % manager.address
        manager.shutdown = util.Finalize(manager,
                                         HostManager._finalize_host,
                                         args=(manager._address,
                                               manager._authkey, cleanup,
                                               host.reverse_cleanup),
                                         exitpriority=-10)
        return manager
    def from_address(cls, address, authkey):
        """
        Return manager given an address.

        address: (ip_addr, port) or string referring to pipe.
            Address to connect to.

        authkey: string
            Authorization key.
        """
        manager = cls(address, authkey)
        conn = connection.Client(address, authkey=authkey)
        try:
            managers.dispatch(conn, None, 'dummy')
        finally:
            conn.close()
        manager._state.value = managers.State.STARTED
        manager._name = 'Host-%s:%s' % manager.address
        manager.shutdown = util.Finalize(
            manager, HostManager._finalize_host,
            args=(manager._address, manager._authkey, manager._name),
            exitpriority=-10
            )
        return manager
    def from_address(cls, address, authkey, host):
        """
        Return manager given an address.

        address: (ip_addr, port) or string referring to pipe.
            Address to connect to.

        authkey: string
            Authorization key.

        host: :class:`Host`
            Host we're managing.
        """
        if host.tunnel_outgoing:
            _LOGGER.debug('Client setting up tunnel for %s:%s',
                          host.hostname, address[1])
            address, cleanup = setup_tunnel(host.hostname, address[1],
                                            identity=host.identity_filename)
        else:
            cleanup = None

        manager = cls(address, authkey)
        _LOGGER.debug('Client connecting to server at %s' % (address,))
        conn = connection.Client(address, authkey=authkey)
        try:
            managers.dispatch(conn, None, 'dummy')
        finally:
            conn.close()
        manager._state.value = managers.State.STARTED
        manager._name = 'Host-%s:%s' % manager.address
        manager.shutdown = util.Finalize(
            manager, HostManager._finalize_host,
            args=(manager._address, manager._authkey,
                  cleanup, host.reverse_cleanup),
            exitpriority=-10)
        return manager