Commits

Brian Kearns committed a411927

wip: checksignals in _file

  • Participants
  • Parent commits f3ee559
  • 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, w_name, mode='r', buffering=-1):
+    def direct___init__(self, space, 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)
+            self.space, w_name, mode, buffering,
+            space.getexecutioncontext().checksignals)
         fd = stream.try_to_find_file_descriptor()
         self.check_not_dir(fd)
         self.fdopenstream(stream, fd, mode)

File rpython/rlib/streamio.py

 
 
 @specialize.argtype(0)
-def open_file_as_stream(path, mode="r", buffering=-1):
+def open_file_as_stream(path, mode="r", buffering=-1, signal_checker=None):
     os_flags, universal, reading, writing, basemode, binary = decode_mode(mode)
-    stream = open_path_helper(path, os_flags, basemode == "a")
+    stream = open_path_helper(path, os_flags, basemode == "a", signal_checker)
     return construct_stream_tower(stream, buffering, universal, reading,
                                   writing, binary)
 
                                   writing, binary)
 
 @specialize.argtype(0)
-def open_path_helper(path, os_flags, append):
+def open_path_helper(path, os_flags, append, signal_checker=None):
     # XXX for now always return DiskFile
     fd = rposix.open(path, os_flags, 0666)
     if append:
         except OSError:
             # XXX does this pass make sense?
             pass
-    return DiskFile(fd)
+    return DiskFile(fd, signal_checker)
 
 def decode_mode(mode):
     if mode[0] == 'U':
 class DiskFile(Stream):
     """Standard I/O basis stream using os.open/close/read/write/lseek"""
 
-    def __init__(self, fd):
+    def __init__(self, fd, signal_checker=None):
         self.fd = fd
+        self.signal_checker = signal_checker
 
     def seek(self, offset, whence):
         os.lseek(self.fd, offset, whence)
             except OSError, e:
                 if e.errno != errno.EINTR:
                     raise
+                if self.signal_checker is not None:
+                    self.signal_checker()
                 # else try again
 
     def readline(self):