mercurial/worker.py
changeset 49231 4d42a5fb70bf
parent 49230 5d28246b9acc
child 49232 4c57ce494a4e
equal deleted inserted replaced
49230:5d28246b9acc 49231:4d42a5fb70bf
    67 def ismainthread():
    67 def ismainthread():
    68     return threading.current_thread() == threading.main_thread()
    68     return threading.current_thread() == threading.main_thread()
    69 
    69 
    70 
    70 
    71 class _blockingreader:
    71 class _blockingreader:
       
    72     """Wrap unbuffered stream such that pickle.load() works with it.
       
    73 
       
    74     pickle.load() expects that calls to read() and readinto() read as many
       
    75     bytes as requested. On EOF, it is fine to read fewer bytes. In this case,
       
    76     pickle.load() raises an EOFError.
       
    77     """
       
    78 
    72     def __init__(self, wrapped):
    79     def __init__(self, wrapped):
    73         self._wrapped = wrapped
    80         self._wrapped = wrapped
    74 
    81 
    75     # Do NOT implement readinto() by making it delegate to
    82     # Do NOT implement readinto() by making it delegate to
    76     # _wrapped.readinto(), since that is unbuffered. The unpickler is fine
    83     # _wrapped.readinto(), since that is unbuffered. The unpickler is fine
    92             return pos
    99             return pos
    93 
   100 
    94     def readline(self):
   101     def readline(self):
    95         return self._wrapped.readline()
   102         return self._wrapped.readline()
    96 
   103 
    97     # issue multiple reads until size is fulfilled
   104     # issue multiple reads until size is fulfilled (or EOF is encountered)
    98     def read(self, size=-1):
   105     def read(self, size=-1):
    99         if size < 0:
   106         if size < 0:
   100             return self._wrapped.readall()
   107             return self._wrapped.readall()
   101 
   108 
   102         buf = bytearray(size)
   109         buf = bytearray(size)