示例#1
0
文件: posixbase.py 项目: pelluch/VTK
 def wakeUp(self):
     """Send a byte to my connection.
     """
     try:
         util.untilConcludes(self.w.send, b"x")
     except socket.error as e:
         if e.args[0] != errno.WSAEWOULDBLOCK:
             raise
示例#2
0
 def wakeUp(self):
     """Send a byte to my connection.
     """
     try:
         util.untilConcludes(self.w.send, b'x')
     except socket.error as e:
         if e.args[0] != errno.WSAEWOULDBLOCK:
             raise
示例#3
0
文件: log.py 项目: AmirKhooj/VTK
    def emit(self, eventDict):
        text = textFromEventDict(eventDict)
        if text is None:
            return

        timeStr = self.formatTime(eventDict['time'])
        fmtDict = {'system': eventDict['system'], 'text': text.replace("\n", "\n\t")}
        msgStr = _safeFormat("[%(system)s] %(text)s\n", fmtDict)

        util.untilConcludes(self.write, timeStr + " " + msgStr)
        util.untilConcludes(self.flush)  # Hoorj!
示例#4
0
 def wakeUp(self):
     """Write one byte to the pipe, and flush it.
     """
     # We don't use fdesc.writeToFD since we need to distinguish
     # between EINTR (try again) and EAGAIN (do nothing).
     if self.o is not None:
         try:
             util.untilConcludes(os.write, self.o, b'x')
         except OSError as e:
             # XXX There is no unit test for raising the exception
             # for other errnos. See #4285.
             if e.errno != errno.EAGAIN:
                 raise
示例#5
0
文件: posixbase.py 项目: pelluch/VTK
 def wakeUp(self):
     """Write one byte to the pipe, and flush it.
     """
     # We don't use fdesc.writeToFD since we need to distinguish
     # between EINTR (try again) and EAGAIN (do nothing).
     if self.o is not None:
         try:
             util.untilConcludes(os.write, self.o, b"x")
         except OSError as e:
             # XXX There is no unit test for raising the exception
             # for other errnos. See #4285.
             if e.errno != errno.EAGAIN:
                 raise
示例#6
0
文件: log.py 项目: steeliter/VTK
    def emit(self, eventDict):
        text = textFromEventDict(eventDict)
        if text is None:
            return

        timeStr = self.formatTime(eventDict['time'])
        fmtDict = {
            'system': eventDict['system'],
            'text': text.replace("\n", "\n\t")
        }
        msgStr = _safeFormat("[%(system)s] %(text)s\n", fmtDict)

        util.untilConcludes(self.write, timeStr + " " + msgStr)
        util.untilConcludes(self.flush)  # Hoorj!
示例#7
0
    def _write(self, format, *args):
        """
        Safely write to the reporter's stream.

        @param format: A format string to write.
        @param *args: The arguments for the format string.
        """
        s = str(format)
        assert isinstance(s, type(''))
        if args:
            self._stream.write(s % args)
        else:
            self._stream.write(s)
        untilConcludes(self._stream.flush)
示例#8
0
 def _execWithFileDescriptor(self, fObj):
     pid = os.fork()
     if pid == 0:
         try:
             os.execv(sys.executable, [sys.executable, '-c', self.program % (fObj.fileno(),)])
         except:
             import traceback
             traceback.print_exc()
             os._exit(30)
     else:
         # On Linux wait(2) doesn't seem ever able to fail with EINTR but
         # POSIX seems to allow it and on OS X it happens quite a lot.
         return untilConcludes(os.waitpid, pid, 0)[1]
示例#9
0
    def test_uninterruptably(self):
        """
        L{untilConcludes} calls the function passed to it until the function
        does not raise either L{OSError} or L{IOError} with C{errno} of
        C{EINTR}.  It otherwise completes with the same result as the function
        passed to it.
        """
        def f(a, b):
            self.calls += 1
            exc = self.exceptions.pop()
            if exc is not None:
                raise exc(errno.EINTR, "Interrupted system call!")
            return a + b

        self.exceptions = [None]
        self.calls = 0
        self.assertEqual(util.untilConcludes(f, 1, 2), 3)
        self.assertEqual(self.calls, 1)

        self.exceptions = [None, OSError, IOError]
        self.calls = 0
        self.assertEqual(util.untilConcludes(f, 2, 3), 5)
        self.assertEqual(self.calls, 3)
示例#10
0
 def _execWithFileDescriptor(self, fObj):
     pid = os.fork()
     if pid == 0:
         try:
             os.execv(
                 sys.executable,
                 [sys.executable, '-c', self.program % (fObj.fileno(), )])
         except:
             import traceback
             traceback.print_exc()
             os._exit(30)
     else:
         # On Linux wait(2) doesn't seem ever able to fail with EINTR but
         # POSIX seems to allow it and on OS X it happens quite a lot.
         return untilConcludes(os.waitpid, pid, 0)[1]
示例#11
0
文件: tcp.py 项目: AmirKhooj/VTK
    def writeSomeData(self, data):
        """
        Write as much as possible of the given data to this TCP connection.

        This sends up to C{self.SEND_LIMIT} bytes from C{data}.  If the
        connection is lost, an exception is returned.  Otherwise, the number
        of bytes successfully written is returned.
        """
        # Limit length of buffer to try to send, because some OSes are too
        # stupid to do so themselves (ahem windows)
        limitedData = lazyByteSlice(data, 0, self.SEND_LIMIT)

        try:
            return untilConcludes(self.socket.send, limitedData)
        except socket.error as se:
            if se.args[0] in (EWOULDBLOCK, ENOBUFS):
                return 0
            else:
                return main.CONNECTION_LOST
示例#12
0
    def writeSomeData(self, data):
        """
        Write as much as possible of the given data to this TCP connection.

        This sends up to C{self.SEND_LIMIT} bytes from C{data}.  If the
        connection is lost, an exception is returned.  Otherwise, the number
        of bytes successfully written is returned.
        """
        # Limit length of buffer to try to send, because some OSes are too
        # stupid to do so themselves (ahem windows)
        limitedData = lazyByteSlice(data, 0, self.SEND_LIMIT)

        try:
            return untilConcludes(self.socket.send, limitedData)
        except socket.error as se:
            if se.args[0] in (EWOULDBLOCK, ENOBUFS):
                return 0
            else:
                return main.CONNECTION_LOST
示例#13
0
 def write(self, *a, **kw):
     return untilConcludes(self.original.write, *a, **kw)