Commits

Brian Kearns committed cf3d6a0

fix signal_checker, use in streamio

  • Participants
  • Parent commits 7db678d
  • Branches stdlib-2.7.6

Comments (0)

Files changed (2)

File pypy/module/_file/interp_file.py

     # file lock.  They don't convert StreamErrors to OperationErrors, too.
 
     @unwrap_spec(mode=str, buffering=int)
-    def direct___init__(self, space, w_name, mode='r', buffering=-1):
+    def direct___init__(self, w_name, mode='r', buffering=-1):
         self.direct_close()
         self.w_name = w_name
         self.check_mode_ok(mode)
         stream = dispatch_filename(streamio.open_file_as_stream)(
-            self.space, w_name, mode, buffering,
-            signal_checker(space))
+            self.space, w_name, mode, buffering, signal_checker(self.space))
         fd = stream.try_to_find_file_descriptor()
         self.check_not_dir(fd)
         self.fdopenstream(stream, fd, mode)
         self.direct_close()
         self.w_name = self.space.wrap('<fdopen>')
         self.check_mode_ok(mode)
-        stream = streamio.fdopen_as_stream(fd, mode, buffering)
+        stream = streamio.fdopen_as_stream(fd, mode, buffering,
+                                           signal_checker(self.space))
         self.fdopenstream(stream, fd, mode)
 
     def direct_close(self):
 
 @specialize.memo()
 def signal_checker(space):
-    return space.getexecutioncontext().checksignals
+    def checksignals():
+        space.getexecutioncontext().checksignals()
+    return checksignals
 
 MAYBE_EAGAIN      = getattr(errno, 'EAGAIN',      None)
 MAYBE_EWOULDBLOCK = getattr(errno, 'EWOULDBLOCK', None)

File rpython/rlib/streamio.py

 def _setfd_binary(fd):
     pass
 
-def fdopen_as_stream(fd, mode, buffering=-1):
+def fdopen_as_stream(fd, mode, buffering=-1, signal_checker=None):
     # XXX XXX XXX you want do check whether the modes are compatible
     # otherwise you get funny results
     os_flags, universal, reading, writing, basemode, binary = decode_mode(mode)
     _setfd_binary(fd)
-    stream = DiskFile(fd)
+    stream = DiskFile(fd, signal_checker)
     return construct_stream_tower(stream, buffering, universal, reading,
                                   writing, binary)
 
             except OSError, e:
                 if e.errno != errno.EINTR:
                     raise
-                else:
-                    continue   # try again
+                if self.signal_checker is not None:
+                    self.signal_checker()
+                continue   # try again
             if not c:
                 break
             c = c[0]
             except OSError, e:
                 if e.errno != errno.EINTR:
                     raise
+                if self.signal_checker is not None:
+                    self.signal_checker()
             else:
                 data = data[n:]