Changeset 391 for python/trunk/Lib/multiprocessing/connection.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/multiprocessing/connection.py
r2 r391 4 4 # multiprocessing/connection.py 5 5 # 6 # Copyright (c) 2006-2008, R Oudkerk --- see COPYING.txt 6 # Copyright (c) 2006-2008, R Oudkerk 7 # All rights reserved. 8 # 9 # Redistribution and use in source and binary forms, with or without 10 # modification, are permitted provided that the following conditions 11 # are met: 12 # 13 # 1. Redistributions of source code must retain the above copyright 14 # notice, this list of conditions and the following disclaimer. 15 # 2. Redistributions in binary form must reproduce the above copyright 16 # notice, this list of conditions and the following disclaimer in the 17 # documentation and/or other materials provided with the distribution. 18 # 3. Neither the name of author nor the names of any contributors may be 19 # used to endorse or promote products derived from this software 20 # without specific prior written permission. 21 # 22 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND 23 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 26 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 # SUCH DAMAGE. 7 33 # 8 34 … … 161 187 if duplex: 162 188 s1, s2 = socket.socketpair() 189 s1.setblocking(True) 190 s2.setblocking(True) 163 191 c1 = _multiprocessing.Connection(os.dup(s1.fileno())) 164 192 c2 = _multiprocessing.Connection(os.dup(s2.fileno())) … … 173 201 174 202 else: 175 176 from ._multiprocessing import win32 203 from _multiprocessing import win32 177 204 178 205 def Pipe(duplex=True): … … 224 251 def __init__(self, address, family, backlog=1): 225 252 self._socket = socket.socket(getattr(socket, family)) 226 self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) 227 self._socket.bind(address) 228 self._socket.listen(backlog) 229 self._address = self._socket.getsockname() 253 try: 254 self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) 255 self._socket.setblocking(True) 256 self._socket.bind(address) 257 self._socket.listen(backlog) 258 self._address = self._socket.getsockname() 259 except socket.error: 260 self._socket.close() 261 raise 230 262 self._family = family 231 263 self._last_accepted = None … … 239 271 240 272 def accept(self): 241 s, self._last_accepted = self._socket.accept() 273 while True: 274 try: 275 s, self._last_accepted = self._socket.accept() 276 except socket.error as e: 277 if e.args[0] != errno.EINTR: 278 raise 279 else: 280 break 281 s.setblocking(True) 242 282 fd = duplicate(s.fileno()) 243 283 conn = _multiprocessing.Connection(fd) … … 255 295 Return a connection object connected to the socket given by `address` 256 296 ''' 257 family = address_type(address) 258 s = socket.socket( getattr(socket, family) ) 297 family = getattr(socket, address_type(address)) 259 298 t = _init_timeout() 260 299 261 300 while 1: 301 s = socket.socket(family) 302 s.setblocking(True) 262 303 try: 263 304 s.connect(address) 264 305 except socket.error, e: 306 s.close() 265 307 if e.args[0] != errno.ECONNREFUSED or _check_timeout(t): 266 308 debug('failed to connect to address %s', address) … … 319 361 win32.ConnectNamedPipe(handle, win32.NULL) 320 362 except WindowsError, e: 321 if e.args[0] != win32.ERROR_PIPE_CONNECTED: 363 # ERROR_NO_DATA can occur if a client has already connected, 364 # written data and then disconnected -- see Issue 14725. 365 if e.args[0] not in (win32.ERROR_PIPE_CONNECTED, 366 win32.ERROR_NO_DATA): 322 367 raise 323 368 return _multiprocessing.PipeConnection(handle)
Note:
See TracChangeset
for help on using the changeset viewer.