Ejemplo n.º 1
0
def create_cmd_skts(class_name, _tmp_dir):
    # Establish an internal connection anchored by a pair of stream sockets by
    # which other threads may deliver cmds to this thread. (The actual cmd
    # calls wrap all access to the sockets and connection.):
    socket_name = os.path.join(_tmp_dir,
                               (class_name + '.%d') % threading.gettid())

    # Delete any existing file with the path & name of the socket to be
    # created:
    while os.path.exists(socket_name):
        try:
            os.remove(socket_name)
        except:
            socket_name += 'x'

    # Create UNIX listen_skt object:
    listen_skt = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)

    # Set this_socket to allow rebinding to different local connections while
    # a previous binding is "in the process" of disconnecting (can take up to
    # several minutes after binding is already disconnected...):
    try:
        listen_skt.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    except Exception, e:
        debug_print(0, '%s Set reuse failed, %s', g_str_create_cmd_skts, e)
Ejemplo n.º 2
0
 def _setup_socketname(self):
     socket_name = os.path.join(TMPDIR, 'SocketTrigger.%d' % gettid())
     while os.path.exists(socket_name):
         try:
             os.remove(socket_name)
         except:
             socket_name += 'x'
     self._socket_name = socket_name
Ejemplo n.º 3
0
 def _setup_socketname(self):
     socket_name = os.path.join(TMPDIR,'SocketTrigger.%d' % gettid())
     while os.path.exists(socket_name):
         try:
             os.remove(socket_name)
         except:
             socket_name += 'x'
     self._socket_name = socket_name
Ejemplo n.º 4
0
 def __unused_socket_name(self, suffix):
     while True:
         socket_name = os.path.join(
             TMP_DIR, 'SocketMapNotifier-%d.%04d' % (gettid(), suffix))
         if not self.usednames.has_key(socket_name):
             return socket_name, suffix
         suffix += 1
     raise EUnreachable()
Ejemplo n.º 5
0
 def __unused_socket_name(self, suffix):
     while True:
         socket_name = os.path.join(
             TMP_DIR, 'SocketMapNotifier-%d.%04d' % (gettid(), suffix)
             )
         if not self.usednames.has_key(socket_name):
             return socket_name, suffix
         suffix += 1
     raise EUnreachable()
Ejemplo n.º 6
0
 def __init__(self):
     self._lock = Lock()
     self._locks = []
     socket_name = os.path.join(_tmp_dir,
                                'Scheduler.%d' % gettid())
     while os.path.exists(socket_name):
         try:    os.remove(socket_name)
         except: socket_name += 'x'
     s_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
     try:
         s_socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR, 
                             s_socket.getsockopt(socket.SOL_SOCKET,
                                                 socket.SO_REUSEADDR)|1)
     except Exception, e:
         print 'set reuse failed, %s' % e
Ejemplo n.º 7
0
 def __init__(self):
     self._lock = Lock()
     self._locks = []
     socket_name = os.path.join(_tmp_dir, 'Scheduler.%d' % gettid())
     while os.path.exists(socket_name):
         try:
             os.remove(socket_name)
         except:
             socket_name += 'x'
     s_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
     try:
         s_socket.setsockopt(
             socket.SOL_SOCKET, socket.SO_REUSEADDR,
             s_socket.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR)
             | 1)
     except Exception, e:
         print 'set reuse failed, %s' % e
Ejemplo n.º 8
0
def create_cmd_skts(class_name, _tmp_dir):
    # Establish an internal connection anchored by a pair of stream sockets by
    # which other threads may deliver cmds to this thread. (The actual cmd
    # calls wrap all access to the sockets and connection.):
    socket_name = os.path.join(_tmp_dir,
                               (class_name + '.%d') % threading.gettid())

    # Delete any existing file with the path & name of the socket to be
    # created:
    while os.path.exists(socket_name):
        try:    os.remove(socket_name)
        except: socket_name += 'x'

    # Create UNIX listen_skt object:
    listen_skt = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)

    # Set this_socket to allow rebinding to different local connections while
    # a previous binding is "in the process" of disconnecting (can take up to
    # several minutes after binding is already disconnected...):
    try:
        listen_skt.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    except Exception, e:
        debug_print(0, '%s Set reuse failed, %s', g_str_create_cmd_skts, e)