Ejemplo n.º 1
0
    def get_listen_addr(self):
        ip = None

        # if fiber.current_process() is multiprocessing.current_process():
        if not isinstance(fiber.current_process(), fiber.Process):
            # not inside docker
            # logger.debug("use interface docker0")
            ifce = "eth0"
            ip = find_ip_by_net_interface(ifce)
        else:
            # inside a Fiber process
            # logger.debug("use interface eth0")
            # ip = find_ip_by_net_interface("eth0")
            ip, ifce = find_listen_address()

        # ip = find_ip_by_net_interface(ifce)
        if ip is None:
            raise mp.ProcessError(
                "Can't find a usable IPv4 address to listen. ifce_name: {}, "
                "ifces: {}".format(ifce, psutil.net_if_addrs()))
        # use 0 to bind to a random free port number
        return ip, 0, ifce
Ejemplo n.º 2
0
    def get_listen_addr(self):
        ip = None

        if sys.platform == "darwin":
            # use the same hostname for both master and non master process
            # because docker.for.mac.localhost resolves to different inside
            # and outside docker container. "docker.for.mac.localhost" is
            # the name that doesn't change in and outside the container.
            return "docker.for.mac.localhost", 0

        if not isinstance(fiber.current_process(), fiber.Process):
            # not inside docker
            ifce = "docker0"
            ip = find_ip_by_net_interface(ifce)
        else:
            # inside a Fiber process
            ip, ifce = find_listen_address()

        if ip is None:
            raise mp.ProcessError(
                "Can't find a usable IPv4 address to listen. ifce_name: {}, "
                "ifces: {}".format(ifce, psutil.net_if_addrs()))
        # use 0 to bind to a random free port number
        return ip, 0, ifce
Ejemplo n.º 3
0
def get_current_pid(q):
    import fiber
    pid = q.get()
    assert fiber.current_process().pid == pid
Ejemplo n.º 4
0
 def test_current_process(self):
     c = fiber.current_process()
     assert c.pid > 0