Commit 2f610df6 authored by Yuxin Wu's avatar Yuxin Wu

use abstract sockets on linux (#455)

parent ea623424
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
# File: parallel.py # File: parallel.py
import sys
import weakref import weakref
from contextlib import contextmanager from contextlib import contextmanager
import multiprocessing as mp import multiprocessing as mp
...@@ -42,15 +42,22 @@ def _bind_guard(sock, name): ...@@ -42,15 +42,22 @@ def _bind_guard(sock, name):
def _get_pipe_name(name): def _get_pipe_name(name):
pipedir = os.environ.get('TENSORPACK_PIPEDIR', None) if sys.platform.startswith('linux'):
if pipedir is not None: # linux supports abstract sockets: http://api.zeromq.org/4-1:zmq-ipc
logger.info("ZMQ uses TENSORPACK_PIPEDIR={}".format(pipedir)) pipename = "ipc://@{}-pipe-{}".format(name, str(uuid.uuid1())[:8])
pipedir = os.environ.get('TENSORPACK_PIPEDIR', None)
if pipedir is not None:
logger.warn("TENSORPACK_PIPEDIR is not used on Linux any more! Abstract sockets will be used.")
else: else:
pipedir = '.' pipedir = os.environ.get('TENSORPACK_PIPEDIR', None)
assert os.path.isdir(pipedir), pipedir if pipedir is not None:
filename = '{}/{}-pipe-{}'.format(pipedir.rstrip('/'), name, str(uuid.uuid1())[:6]) logger.info("ZMQ uses TENSORPACK_PIPEDIR={}".format(pipedir))
assert not os.path.exists(filename), "Pipe {} exists! You may be unlucky.".format(filename) else:
pipename = "ipc://{}".format(filename) pipedir = '.'
assert os.path.isdir(pipedir), pipedir
filename = '{}/{}-pipe-{}'.format(pipedir.rstrip('/'), name, str(uuid.uuid1())[:6])
assert not os.path.exists(filename), "Pipe {} exists! You may be unlucky.".format(filename)
pipename = "ipc://{}".format(filename)
return pipename return pipename
......
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