Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(6)

Side by Side Diff: Lib/multiprocessing/connection.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/logging/__init__.py ('k') | Lib/multiprocessing/heap.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # 1 #
2 # A higher level module for using sockets (or Windows named pipes) 2 # A higher level module for using sockets (or Windows named pipes)
3 # 3 #
4 # multiprocessing/connection.py 4 # multiprocessing/connection.py
5 # 5 #
6 # Copyright (c) 2006-2008, R Oudkerk 6 # Copyright (c) 2006-2008, R Oudkerk
7 # All rights reserved. 7 # All rights reserved.
8 # 8 #
9 # Redistribution and use in source and binary forms, with or without 9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions 10 # modification, are permitted provided that the following conditions
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 def __init__(self, handle, readable=True, writable=True): 141 def __init__(self, handle, readable=True, writable=True):
142 handle = handle.__index__() 142 handle = handle.__index__()
143 if handle < 0: 143 if handle < 0:
144 raise ValueError("invalid handle") 144 raise ValueError("invalid handle")
145 if not readable and not writable: 145 if not readable and not writable:
146 raise ValueError( 146 raise ValueError(
147 "at least one of `readable` and `writable` must be True") 147 "at least one of `readable` and `writable` must be True")
148 self._handle = handle 148 self._handle = handle
149 self._readable = readable 149 self._readable = readable
150 self._writable = writable 150 self._writable = writable
151
152 # XXX should we use util.Finalize instead of a __del__?
153 151
154 def __del__(self): 152 def __del__(self):
155 if self._handle is not None: 153 if self._handle is not None:
156 self._close() 154 self._close()
157 155
158 def _check_closed(self): 156 def _check_closed(self):
159 if self._handle is None: 157 if self._handle is None:
160 raise IOError("handle is closed") 158 raise IOError("handle is closed")
161 159
162 def _check_readable(self): 160 def _check_readable(self):
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 if win32: 283 if win32:
286 284
287 class PipeConnection(_ConnectionBase): 285 class PipeConnection(_ConnectionBase):
288 """ 286 """
289 Connection class based on a Windows named pipe. 287 Connection class based on a Windows named pipe.
290 Overlapped I/O is used, so the handles must have been created 288 Overlapped I/O is used, so the handles must have been created
291 with FILE_FLAG_OVERLAPPED. 289 with FILE_FLAG_OVERLAPPED.
292 """ 290 """
293 _buffered = b'' 291 _buffered = b''
294 292
295 def _close(self, _CloseHandle=win32.CloseHandle): 293 def _close(self):
296 _CloseHandle(self._handle) 294 win32.CloseHandle(self._handle)
297 295
298 def _send_bytes(self, buf): 296 def _send_bytes(self, buf):
299 overlapped = win32.WriteFile(self._handle, buf, overlapped=True) 297 overlapped = win32.WriteFile(self._handle, buf, overlapped=True)
300 nwritten, complete = overlapped.GetOverlappedResult(True) 298 nwritten, complete = overlapped.GetOverlappedResult(True)
301 assert complete 299 assert complete
302 assert nwritten == len(buf) 300 assert nwritten == len(buf)
303 301
304 def _recv_bytes(self, maxsize=None, sentinels=()): 302 def _recv_bytes(self, maxsize=None, sentinels=()):
305 if sentinels: 303 if sentinels:
306 self._poll(-1.0, sentinels) 304 self._poll(-1.0, sentinels)
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 raise SentinelReady([handles[idx]]) 369 raise SentinelReady([handles[idx]])
372 370
373 371
374 class Connection(_ConnectionBase): 372 class Connection(_ConnectionBase):
375 """ 373 """
376 Connection class based on an arbitrary file descriptor (Unix only), or 374 Connection class based on an arbitrary file descriptor (Unix only), or
377 a socket handle (Windows). 375 a socket handle (Windows).
378 """ 376 """
379 377
380 if win32: 378 if win32:
381 def _close(self, _close=win32.closesocket): 379 def _close(self):
382 _close(self._handle) 380 win32.closesocket(self._handle)
383 _write = win32.send 381 _write = win32.send
384 _read = win32.recv 382 _read = win32.recv
385 else: 383 else:
386 def _close(self, _close=os.close): 384 def _close(self):
387 _close(self._handle) 385 os.close(self._handle)
388 _write = os.write 386 _write = os.write
389 _read = os.read 387 _read = os.read
390 388
391 def _send(self, buf, write=_write): 389 def _send(self, buf, write=_write):
392 remaining = len(buf) 390 remaining = len(buf)
393 while True: 391 while True:
394 n = write(self._handle, buf) 392 n = write(self._handle, buf)
395 remaining -= n 393 remaining -= n
396 if remaining == 0: 394 if remaining == 0:
397 break 395 break
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 return ConnectionWrapper(obj, _xml_dumps, _xml_loads) 772 return ConnectionWrapper(obj, _xml_dumps, _xml_loads)
775 773
776 def XmlClient(*args, **kwds): 774 def XmlClient(*args, **kwds):
777 global xmlrpclib 775 global xmlrpclib
778 import xmlrpc.client as xmlrpclib 776 import xmlrpc.client as xmlrpclib
779 return ConnectionWrapper(Client(*args, **kwds), _xml_dumps, _xml_loads) 777 return ConnectionWrapper(Client(*args, **kwds), _xml_dumps, _xml_loads)
780 778
781 779
782 # Late import because of circular import 780 # Late import because of circular import
783 from multiprocessing.forking import duplicate, close 781 from multiprocessing.forking import duplicate, close
OLDNEW
« no previous file with comments | « Lib/logging/__init__.py ('k') | Lib/multiprocessing/heap.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+