51
51
from multiprocessing .util import (
52
52
get_temp_dir , Finalize , sub_debug , debug , _eintr_retry )
53
53
try :
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
56
56
except ImportError :
57
57
if sys .platform == 'win32' :
58
58
raise
59
- win32 = None
59
+ _winapi = None
60
60
61
61
#
62
62
#
@@ -282,7 +282,7 @@ def poll(self, timeout=0.0):
282
282
return self ._poll (timeout )
283
283
284
284
285
- if win32 :
285
+ if _winapi :
286
286
287
287
class PipeConnection (_ConnectionBase ):
288
288
"""
@@ -292,14 +292,14 @@ class PipeConnection(_ConnectionBase):
292
292
"""
293
293
_got_empty_message = False
294
294
295
- def _close (self , _CloseHandle = win32 .CloseHandle ):
295
+ def _close (self , _CloseHandle = _winapi .CloseHandle ):
296
296
_CloseHandle (self ._handle )
297
297
298
298
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 )
300
300
try :
301
- if err == win32 .ERROR_IO_PENDING :
302
- waitres = win32 .WaitForMultipleObjects (
301
+ if err == _winapi .ERROR_IO_PENDING :
302
+ waitres = _winapi .WaitForMultipleObjects (
303
303
[ov .event ], False , INFINITE )
304
304
assert waitres == WAIT_OBJECT_0
305
305
except :
@@ -317,11 +317,11 @@ def _recv_bytes(self, maxsize=None):
317
317
else :
318
318
bsize = 128 if maxsize is None else min (maxsize , 128 )
319
319
try :
320
- ov , err = win32 .ReadFile (self ._handle , bsize ,
321
- overlapped = True )
320
+ ov , err = _winapi .ReadFile (self ._handle , bsize ,
321
+ overlapped = True )
322
322
try :
323
- if err == win32 .ERROR_IO_PENDING :
324
- waitres = win32 .WaitForMultipleObjects (
323
+ if err == _winapi .ERROR_IO_PENDING :
324
+ waitres = _winapi .WaitForMultipleObjects (
325
325
[ov .event ], False , INFINITE )
326
326
assert waitres == WAIT_OBJECT_0
327
327
except :
@@ -333,18 +333,18 @@ def _recv_bytes(self, maxsize=None):
333
333
f = io .BytesIO ()
334
334
f .write (ov .getbuffer ())
335
335
return f
336
- elif err == win32 .ERROR_MORE_DATA :
336
+ elif err == _winapi .ERROR_MORE_DATA :
337
337
return self ._get_more_data (ov , maxsize )
338
338
except IOError as e :
339
- if e .winerror == win32 .ERROR_BROKEN_PIPE :
339
+ if e .winerror == _winapi .ERROR_BROKEN_PIPE :
340
340
raise EOFError
341
341
else :
342
342
raise
343
343
raise RuntimeError ("shouldn't get here; expected KeyboardInterrupt" )
344
344
345
345
def _poll (self , timeout ):
346
346
if (self ._got_empty_message or
347
- win32 .PeekNamedPipe (self ._handle )[0 ] != 0 ):
347
+ _winapi .PeekNamedPipe (self ._handle )[0 ] != 0 ):
348
348
return True
349
349
if timeout < 0 :
350
350
timeout = None
@@ -354,11 +354,11 @@ def _get_more_data(self, ov, maxsize):
354
354
buf = ov .getbuffer ()
355
355
f = io .BytesIO ()
356
356
f .write (buf )
357
- left = win32 .PeekNamedPipe (self ._handle )[1 ]
357
+ left = _winapi .PeekNamedPipe (self ._handle )[1 ]
358
358
assert left > 0
359
359
if maxsize is not None and len (buf ) + left > maxsize :
360
360
self ._bad_message_length ()
361
- ov , err = win32 .ReadFile (self ._handle , left , overlapped = True )
361
+ ov , err = _winapi .ReadFile (self ._handle , left , overlapped = True )
362
362
rbytes , err = ov .GetOverlappedResult (True )
363
363
assert err == 0
364
364
assert rbytes == left
@@ -372,11 +372,11 @@ class Connection(_ConnectionBase):
372
372
a socket handle (Windows).
373
373
"""
374
374
375
- if win32 :
376
- def _close (self , _close = win32 .closesocket ):
375
+ if _winapi :
376
+ def _close (self , _close = _multiprocessing .closesocket ):
377
377
_close (self ._handle )
378
- _write = win32 .send
379
- _read = win32 .recv
378
+ _write = _multiprocessing .send
379
+ _read = _multiprocessing .recv
380
380
else :
381
381
def _close (self , _close = os .close ):
382
382
_close (self ._handle )
@@ -526,30 +526,30 @@ def Pipe(duplex=True):
526
526
'''
527
527
address = arbitrary_address ('AF_PIPE' )
528
528
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
531
531
obsize , ibsize = BUFSIZE , BUFSIZE
532
532
else :
533
- openmode = win32 .PIPE_ACCESS_INBOUND
534
- access = win32 .GENERIC_WRITE
533
+ openmode = _winapi .PIPE_ACCESS_INBOUND
534
+ access = _winapi .GENERIC_WRITE
535
535
obsize , ibsize = 0 , BUFSIZE
536
536
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
543
543
)
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
547
547
)
548
- win32 .SetNamedPipeHandleState (
549
- h2 , win32 .PIPE_READMODE_MESSAGE , None , None
548
+ _winapi .SetNamedPipeHandleState (
549
+ h2 , _winapi .PIPE_READMODE_MESSAGE , None , None
550
550
)
551
551
552
- overlapped = win32 .ConnectNamedPipe (h1 , overlapped = True )
552
+ overlapped = _winapi .ConnectNamedPipe (h1 , overlapped = True )
553
553
_ , err = overlapped .GetOverlappedResult (True )
554
554
assert err == 0
555
555
@@ -630,26 +630,26 @@ def __init__(self, address, backlog=None):
630
630
)
631
631
632
632
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
634
634
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 (
637
637
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
642
642
)
643
643
644
644
def accept (self ):
645
645
self ._handle_queue .append (self ._new_handle ())
646
646
handle = self ._handle_queue .pop (0 )
647
- ov = win32 .ConnectNamedPipe (handle , overlapped = True )
647
+ ov = _winapi .ConnectNamedPipe (handle , overlapped = True )
648
648
try :
649
- res = win32 .WaitForMultipleObjects ([ov .event ], False , INFINITE )
649
+ res = _winapi .WaitForMultipleObjects ([ov .event ], False , INFINITE )
650
650
except :
651
651
ov .cancel ()
652
- win32 .CloseHandle (handle )
652
+ _winapi .CloseHandle (handle )
653
653
raise
654
654
finally :
655
655
_ , err = ov .GetOverlappedResult (True )
@@ -660,7 +660,7 @@ def accept(self):
660
660
def _finalize_pipe_listener (queue , address ):
661
661
sub_debug ('closing listener with address=%r' , address )
662
662
for handle in queue :
663
- win32 .CloseHandle (handle )
663
+ _winapi .CloseHandle (handle )
664
664
665
665
def PipeClient (address ):
666
666
'''
@@ -669,23 +669,23 @@ def PipeClient(address):
669
669
t = _init_timeout ()
670
670
while 1 :
671
671
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
677
677
)
678
678
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 ):
681
681
raise
682
682
else :
683
683
break
684
684
else :
685
685
raise
686
686
687
- win32 .SetNamedPipeHandleState (
688
- h , win32 .PIPE_READMODE_MESSAGE , None , None
687
+ _winapi .SetNamedPipeHandleState (
688
+ h , _winapi .PIPE_READMODE_MESSAGE , None , None
689
689
)
690
690
return PipeConnection (h )
691
691
@@ -774,7 +774,7 @@ def _exhaustive_wait(handles, timeout):
774
774
L = list (handles )
775
775
ready = []
776
776
while L :
777
- res = win32 .WaitForMultipleObjects (L , False , timeout )
777
+ res = _winapi .WaitForMultipleObjects (L , False , timeout )
778
778
if res == WAIT_TIMEOUT :
779
779
break
780
780
elif WAIT_OBJECT_0 <= res < WAIT_OBJECT_0 + len (L ):
@@ -788,7 +788,7 @@ def _exhaustive_wait(handles, timeout):
788
788
timeout = 0
789
789
return ready
790
790
791
- _ready_errors = {win32 .ERROR_BROKEN_PIPE , win32 .ERROR_NETNAME_DELETED }
791
+ _ready_errors = {_winapi .ERROR_BROKEN_PIPE , _winapi .ERROR_NETNAME_DELETED }
792
792
793
793
def wait (object_list , timeout = None ):
794
794
'''
@@ -818,12 +818,12 @@ def wait(object_list, timeout=None):
818
818
else :
819
819
# start an overlapped read of length zero
820
820
try :
821
- ov , err = win32 .ReadFile (fileno (), 0 , True )
821
+ ov , err = _winapi .ReadFile (fileno (), 0 , True )
822
822
except OSError as e :
823
823
err = e .winerror
824
824
if err not in _ready_errors :
825
825
raise
826
- if err == win32 .ERROR_IO_PENDING :
826
+ if err == _winapi .ERROR_IO_PENDING :
827
827
ov_list .append (ov )
828
828
waithandle_to_obj [ov .event ] = o
829
829
else :
@@ -847,7 +847,7 @@ def wait(object_list, timeout=None):
847
847
err = e .winerror
848
848
if err not in _ready_errors :
849
849
raise
850
- if err != win32 .ERROR_OPERATION_ABORTED :
850
+ if err != _winapi .ERROR_OPERATION_ABORTED :
851
851
o = waithandle_to_obj [ov .event ]
852
852
ready_objects .add (o )
853
853
if err == 0 :
0 commit comments