5151from multiprocessing .util import (
5252 get_temp_dir , Finalize , sub_debug , debug , _eintr_retry )
5353try :
54- from _multiprocessing import win32
55- from _subprocess import WAIT_OBJECT_0 , WAIT_TIMEOUT , INFINITE
54+ import _winapi
55+ from _winapi import WAIT_OBJECT_0 , WAIT_TIMEOUT , INFINITE
5656except ImportError :
5757 if sys .platform == 'win32' :
5858 raise
59- win32 = None
59+ _winapi = None
6060
6161#
6262#
@@ -282,7 +282,7 @@ def poll(self, timeout=0.0):
282282 return self ._poll (timeout )
283283
284284
285- if win32 :
285+ if _winapi :
286286
287287 class PipeConnection (_ConnectionBase ):
288288 """
@@ -292,14 +292,14 @@ class PipeConnection(_ConnectionBase):
292292 """
293293 _got_empty_message = False
294294
295- def _close (self , _CloseHandle = win32 .CloseHandle ):
295+ def _close (self , _CloseHandle = _winapi .CloseHandle ):
296296 _CloseHandle (self ._handle )
297297
298298 def _send_bytes (self , buf ):
299- ov , err = win32 .WriteFile (self ._handle , buf , overlapped = True )
299+ ov , err = _winapi .WriteFile (self ._handle , buf , overlapped = True )
300300 try :
301- if err == win32 .ERROR_IO_PENDING :
302- waitres = win32 .WaitForMultipleObjects (
301+ if err == _winapi .ERROR_IO_PENDING :
302+ waitres = _winapi .WaitForMultipleObjects (
303303 [ov .event ], False , INFINITE )
304304 assert waitres == WAIT_OBJECT_0
305305 except :
@@ -317,11 +317,11 @@ def _recv_bytes(self, maxsize=None):
317317 else :
318318 bsize = 128 if maxsize is None else min (maxsize , 128 )
319319 try :
320- ov , err = win32 .ReadFile (self ._handle , bsize ,
321- overlapped = True )
320+ ov , err = _winapi .ReadFile (self ._handle , bsize ,
321+ overlapped = True )
322322 try :
323- if err == win32 .ERROR_IO_PENDING :
324- waitres = win32 .WaitForMultipleObjects (
323+ if err == _winapi .ERROR_IO_PENDING :
324+ waitres = _winapi .WaitForMultipleObjects (
325325 [ov .event ], False , INFINITE )
326326 assert waitres == WAIT_OBJECT_0
327327 except :
@@ -333,18 +333,18 @@ def _recv_bytes(self, maxsize=None):
333333 f = io .BytesIO ()
334334 f .write (ov .getbuffer ())
335335 return f
336- elif err == win32 .ERROR_MORE_DATA :
336+ elif err == _winapi .ERROR_MORE_DATA :
337337 return self ._get_more_data (ov , maxsize )
338338 except IOError as e :
339- if e .winerror == win32 .ERROR_BROKEN_PIPE :
339+ if e .winerror == _winapi .ERROR_BROKEN_PIPE :
340340 raise EOFError
341341 else :
342342 raise
343343 raise RuntimeError ("shouldn't get here; expected KeyboardInterrupt" )
344344
345345 def _poll (self , timeout ):
346346 if (self ._got_empty_message or
347- win32 .PeekNamedPipe (self ._handle )[0 ] != 0 ):
347+ _winapi .PeekNamedPipe (self ._handle )[0 ] != 0 ):
348348 return True
349349 if timeout < 0 :
350350 timeout = None
@@ -354,11 +354,11 @@ def _get_more_data(self, ov, maxsize):
354354 buf = ov .getbuffer ()
355355 f = io .BytesIO ()
356356 f .write (buf )
357- left = win32 .PeekNamedPipe (self ._handle )[1 ]
357+ left = _winapi .PeekNamedPipe (self ._handle )[1 ]
358358 assert left > 0
359359 if maxsize is not None and len (buf ) + left > maxsize :
360360 self ._bad_message_length ()
361- ov , err = win32 .ReadFile (self ._handle , left , overlapped = True )
361+ ov , err = _winapi .ReadFile (self ._handle , left , overlapped = True )
362362 rbytes , err = ov .GetOverlappedResult (True )
363363 assert err == 0
364364 assert rbytes == left
@@ -372,11 +372,11 @@ class Connection(_ConnectionBase):
372372 a socket handle (Windows).
373373 """
374374
375- if win32 :
376- def _close (self , _close = win32 .closesocket ):
375+ if _winapi :
376+ def _close (self , _close = _multiprocessing .closesocket ):
377377 _close (self ._handle )
378- _write = win32 .send
379- _read = win32 .recv
378+ _write = _multiprocessing .send
379+ _read = _multiprocessing .recv
380380 else :
381381 def _close (self , _close = os .close ):
382382 _close (self ._handle )
@@ -526,30 +526,30 @@ def Pipe(duplex=True):
526526 '''
527527 address = arbitrary_address ('AF_PIPE' )
528528 if duplex :
529- openmode = win32 .PIPE_ACCESS_DUPLEX
530- access = win32 .GENERIC_READ | win32 .GENERIC_WRITE
529+ openmode = _winapi .PIPE_ACCESS_DUPLEX
530+ access = _winapi .GENERIC_READ | _winapi .GENERIC_WRITE
531531 obsize , ibsize = BUFSIZE , BUFSIZE
532532 else :
533- openmode = win32 .PIPE_ACCESS_INBOUND
534- access = win32 .GENERIC_WRITE
533+ openmode = _winapi .PIPE_ACCESS_INBOUND
534+ access = _winapi .GENERIC_WRITE
535535 obsize , ibsize = 0 , BUFSIZE
536536
537- h1 = win32 .CreateNamedPipe (
538- address , openmode | win32 .FILE_FLAG_OVERLAPPED |
539- win32 .FILE_FLAG_FIRST_PIPE_INSTANCE ,
540- win32 .PIPE_TYPE_MESSAGE | win32 .PIPE_READMODE_MESSAGE |
541- win32 .PIPE_WAIT ,
542- 1 , obsize , ibsize , win32 .NMPWAIT_WAIT_FOREVER , win32 .NULL
537+ h1 = _winapi .CreateNamedPipe (
538+ address , openmode | _winapi .FILE_FLAG_OVERLAPPED |
539+ _winapi .FILE_FLAG_FIRST_PIPE_INSTANCE ,
540+ _winapi .PIPE_TYPE_MESSAGE | _winapi .PIPE_READMODE_MESSAGE |
541+ _winapi .PIPE_WAIT ,
542+ 1 , obsize , ibsize , _winapi .NMPWAIT_WAIT_FOREVER , _winapi .NULL
543543 )
544- h2 = win32 .CreateFile (
545- address , access , 0 , win32 .NULL , win32 .OPEN_EXISTING ,
546- win32 .FILE_FLAG_OVERLAPPED , win32 .NULL
544+ h2 = _winapi .CreateFile (
545+ address , access , 0 , _winapi .NULL , _winapi .OPEN_EXISTING ,
546+ _winapi .FILE_FLAG_OVERLAPPED , _winapi .NULL
547547 )
548- win32 .SetNamedPipeHandleState (
549- h2 , win32 .PIPE_READMODE_MESSAGE , None , None
548+ _winapi .SetNamedPipeHandleState (
549+ h2 , _winapi .PIPE_READMODE_MESSAGE , None , None
550550 )
551551
552- overlapped = win32 .ConnectNamedPipe (h1 , overlapped = True )
552+ overlapped = _winapi .ConnectNamedPipe (h1 , overlapped = True )
553553 _ , err = overlapped .GetOverlappedResult (True )
554554 assert err == 0
555555
@@ -630,26 +630,26 @@ def __init__(self, address, backlog=None):
630630 )
631631
632632 def _new_handle (self , first = False ):
633- flags = win32 .PIPE_ACCESS_DUPLEX | win32 .FILE_FLAG_OVERLAPPED
633+ flags = _winapi .PIPE_ACCESS_DUPLEX | _winapi .FILE_FLAG_OVERLAPPED
634634 if first :
635- flags |= win32 .FILE_FLAG_FIRST_PIPE_INSTANCE
636- return win32 .CreateNamedPipe (
635+ flags |= _winapi .FILE_FLAG_FIRST_PIPE_INSTANCE
636+ return _winapi .CreateNamedPipe (
637637 self ._address , flags ,
638- win32 .PIPE_TYPE_MESSAGE | win32 .PIPE_READMODE_MESSAGE |
639- win32 .PIPE_WAIT ,
640- win32 .PIPE_UNLIMITED_INSTANCES , BUFSIZE , BUFSIZE ,
641- win32 .NMPWAIT_WAIT_FOREVER , win32 .NULL
638+ _winapi .PIPE_TYPE_MESSAGE | _winapi .PIPE_READMODE_MESSAGE |
639+ _winapi .PIPE_WAIT ,
640+ _winapi .PIPE_UNLIMITED_INSTANCES , BUFSIZE , BUFSIZE ,
641+ _winapi .NMPWAIT_WAIT_FOREVER , _winapi .NULL
642642 )
643643
644644 def accept (self ):
645645 self ._handle_queue .append (self ._new_handle ())
646646 handle = self ._handle_queue .pop (0 )
647- ov = win32 .ConnectNamedPipe (handle , overlapped = True )
647+ ov = _winapi .ConnectNamedPipe (handle , overlapped = True )
648648 try :
649- res = win32 .WaitForMultipleObjects ([ov .event ], False , INFINITE )
649+ res = _winapi .WaitForMultipleObjects ([ov .event ], False , INFINITE )
650650 except :
651651 ov .cancel ()
652- win32 .CloseHandle (handle )
652+ _winapi .CloseHandle (handle )
653653 raise
654654 finally :
655655 _ , err = ov .GetOverlappedResult (True )
@@ -660,7 +660,7 @@ def accept(self):
660660 def _finalize_pipe_listener (queue , address ):
661661 sub_debug ('closing listener with address=%r' , address )
662662 for handle in queue :
663- win32 .CloseHandle (handle )
663+ _winapi .CloseHandle (handle )
664664
665665 def PipeClient (address ):
666666 '''
@@ -669,23 +669,23 @@ def PipeClient(address):
669669 t = _init_timeout ()
670670 while 1 :
671671 try :
672- win32 .WaitNamedPipe (address , 1000 )
673- h = win32 .CreateFile (
674- address , win32 .GENERIC_READ | win32 .GENERIC_WRITE ,
675- 0 , win32 .NULL , win32 .OPEN_EXISTING ,
676- win32 .FILE_FLAG_OVERLAPPED , win32 .NULL
672+ _winapi .WaitNamedPipe (address , 1000 )
673+ h = _winapi .CreateFile (
674+ address , _winapi .GENERIC_READ | _winapi .GENERIC_WRITE ,
675+ 0 , _winapi .NULL , _winapi .OPEN_EXISTING ,
676+ _winapi .FILE_FLAG_OVERLAPPED , _winapi .NULL
677677 )
678678 except WindowsError as e :
679- if e .winerror not in (win32 .ERROR_SEM_TIMEOUT ,
680- win32 .ERROR_PIPE_BUSY ) or _check_timeout (t ):
679+ if e .winerror not in (_winapi .ERROR_SEM_TIMEOUT ,
680+ _winapi .ERROR_PIPE_BUSY ) or _check_timeout (t ):
681681 raise
682682 else :
683683 break
684684 else :
685685 raise
686686
687- win32 .SetNamedPipeHandleState (
688- h , win32 .PIPE_READMODE_MESSAGE , None , None
687+ _winapi .SetNamedPipeHandleState (
688+ h , _winapi .PIPE_READMODE_MESSAGE , None , None
689689 )
690690 return PipeConnection (h )
691691
@@ -774,7 +774,7 @@ def _exhaustive_wait(handles, timeout):
774774 L = list (handles )
775775 ready = []
776776 while L :
777- res = win32 .WaitForMultipleObjects (L , False , timeout )
777+ res = _winapi .WaitForMultipleObjects (L , False , timeout )
778778 if res == WAIT_TIMEOUT :
779779 break
780780 elif WAIT_OBJECT_0 <= res < WAIT_OBJECT_0 + len (L ):
@@ -788,7 +788,7 @@ def _exhaustive_wait(handles, timeout):
788788 timeout = 0
789789 return ready
790790
791- _ready_errors = {win32 .ERROR_BROKEN_PIPE , win32 .ERROR_NETNAME_DELETED }
791+ _ready_errors = {_winapi .ERROR_BROKEN_PIPE , _winapi .ERROR_NETNAME_DELETED }
792792
793793 def wait (object_list , timeout = None ):
794794 '''
@@ -818,12 +818,12 @@ def wait(object_list, timeout=None):
818818 else :
819819 # start an overlapped read of length zero
820820 try :
821- ov , err = win32 .ReadFile (fileno (), 0 , True )
821+ ov , err = _winapi .ReadFile (fileno (), 0 , True )
822822 except OSError as e :
823823 err = e .winerror
824824 if err not in _ready_errors :
825825 raise
826- if err == win32 .ERROR_IO_PENDING :
826+ if err == _winapi .ERROR_IO_PENDING :
827827 ov_list .append (ov )
828828 waithandle_to_obj [ov .event ] = o
829829 else :
@@ -847,7 +847,7 @@ def wait(object_list, timeout=None):
847847 err = e .winerror
848848 if err not in _ready_errors :
849849 raise
850- if err != win32 .ERROR_OPERATION_ABORTED :
850+ if err != _winapi .ERROR_OPERATION_ABORTED :
851851 o = waithandle_to_obj [ov .event ]
852852 ready_objects .add (o )
853853 if err == 0 :
0 commit comments