Example #1
0
    def fileno(self):
        """
        Returns an OS-level file descriptor which can be used for polling, but
        but not for reading or writing.  This is primarily to allow Python's
        ``select`` module to work.

        The first time ``fileno`` is called on a channel, a pipe is created to
        simulate real OS-level file descriptor (FD) behavior.  Because of this,
        two OS-level FDs are created, which will use up FDs faster than normal.
        (You won't notice this effect unless you have hundreds of channels
        open at the same time.)

        :return: an OS-level file descriptor (`int`)

        .. warning::
            This method causes channel reads to be slightly less efficient.
        """
        self.lock.acquire()
        try:
            if self._pipe is not None:
                return self._pipe.fileno()
            # create the pipe and feed in any existing data
            self._pipe = pipe.make_pipe()
            p1, p2 = pipe.make_or_pipe(self._pipe)
            self.in_buffer.set_event(p1)
            self.in_stderr_buffer.set_event(p2)
            return self._pipe.fileno()
        finally:
            self.lock.release()
Example #2
0
    def fileno(self):
        """
        Returns an OS-level file descriptor which can be used for polling, but
        but not for reading or writing.  This is primarily to allow Python's
        ``select`` modules to work.

        The first time ``fileno`` is called on a channel, a pipe is created to
        simulate real OS-level file descriptor (FD) behavior.  Because of this,
        two OS-level FDs are created, which will use up FDs faster than normal.
        (You won't notice this effect unless you have hundreds of channels
        open at the same time.)

        :return: an OS-level file descriptor (`int`)

        .. warning::
            This method causes channel reads to be slightly less efficient.
        """
        self.lock.acquire()
        try:
            if self._pipe is not None:
                return self._pipe.fileno()
            # create the pipe and feed in any existing data
            self._pipe = pipe.make_pipe()
            p1, p2 = pipe.make_or_pipe(self._pipe)
            self.in_buffer.set_event(p1)
            self.in_stderr_buffer.set_event(p2)
            return self._pipe.fileno()
        finally:
            self.lock.release()
Example #3
0
    def fileno(self):
        """
        Returns an OS-level file descriptor which can be used for polling, but
        but I{not} for reading or writing).  This is primaily to allow python's
        C{select} module to work.

        The first time C{fileno} is called on a channel, a pipe is created to
        simulate real OS-level file descriptor (FD) behavior.  Because of this,
        two OS-level FDs are created, which will use up FDs faster than normal.
        You won't notice this effect unless you open hundreds or thousands of
        channels simultaneously, but it's still notable.

        @return: an OS-level file descriptor
        @rtype: int
        
        @warning: This method causes channel reads to be slightly less
            efficient.
        """
        self.lock.acquire()
        try:
            if self.pipe is not None:
                return self.pipe.fileno()
            # create the pipe and feed in any existing data
            self.pipe = pipe.make_pipe()
            if len(self.in_buffer) > 0:
                self.pipe.set()
            return self.pipe.fileno()
        finally:
            self.lock.release()
Example #4
0
    def fileno(self):
        """
        Returns an OS-level file descriptor which can be used for polling, but
        but I{not} for reading or writing).  This is primaily to allow python's
        C{select} module to work.

        The first time C{fileno} is called on a channel, a pipe is created to
        simulate real OS-level file descriptor (FD) behavior.  Because of this,
        two OS-level FDs are created, which will use up FDs faster than normal.
        You won't notice this effect unless you open hundreds or thousands of
        channels simultaneously, but it's still notable.

        @return: an OS-level file descriptor
        @rtype: int
        
        @warning: This method causes channel reads to be slightly less
            efficient.
        """
        self.lock.acquire()
        try:
            if self.pipe is not None:
                return self.pipe.fileno()
            # create the pipe and feed in any existing data
            self.pipe = pipe.make_pipe()
            if len(self.in_buffer) > 0:
                self.pipe.set()
            return self.pipe.fileno()
        finally:
            self.lock.release()
 def test_4_or_pipe(self):
     p = pipe.make_pipe()
     p1, p2 = pipe.make_or_pipe(p)
     self.assertFalse(p._set)
     p1.set()
     self.assertTrue(p._set)
     p2.set()
     self.assertTrue(p._set)
     p1.clear()
     self.assertTrue(p._set)
     p2.clear()
     self.assertFalse(p._set)
Example #6
0
 def test_4_or_pipe(self):
     p = pipe.make_pipe()
     p1, p2 = pipe.make_or_pipe(p)
     self.assertFalse(p._set)
     p1.set()
     self.assertTrue(p._set)
     p2.set()
     self.assertTrue(p._set)
     p1.clear()
     self.assertTrue(p._set)
     p2.clear()
     self.assertFalse(p._set)