classification
Title: multiprocessing/win32: WindowsError: [Error 0] Success on Pipe()
Type: behavior Stage: test needed
Components: Extension Modules, Windows Versions: Python 2.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: amyodov, asksol, brian.curtin, jnoller
Priority: normal Keywords:

Created on 2010-06-28 12:54 by amyodov, last changed 2011-06-06 17:44 by amyodov.

Messages (4)
msg108824 - (view) Author: Alexander Myodov (amyodov) Date: 2010-06-28 12:54
I am using Python 2.6.5/win32, and working with multiprocessing module, doing that with Python interpreter embedded using Cython (if that may be related to the problem).

While creating a subprocess and a Pipe to communicate with it, I've got the following traceback (particulaly on the line "parent_conn, child_conn = Pipe()"):

Traceback (most recent call last):
  File "test_fork.py", line 24, in init test_fork (test_fork.c:810)
    vasia.main()
  File "Z:\multiprocessing_cython_w32\vasia.py", line 15, in main
    parent_conn, child_conn = Pipe()
  File "Z:\python-win32\2.6.5\Lib\multiprocessing\__init__.py", line 106, in Pipe
    return Pipe(duplex)
  File "Z:\python-win32\2.6.5\Lib\multiprocessing\connection.py", line 202, in Pipe
    h2, win32.PIPE_READMODE_MESSAGE, None, None
WindowsError: [Error 0] Success

Lines 202-204 in multiprocessing/connection.py contain the following: 

        win32.SetNamedPipeHandleState(                                                                                             
            h2, win32.PIPE_READMODE_MESSAGE, None, None                                                                            
            ) 

It seems to me that for some reason SetNamedPipeHandleState might be returning 0 even while it didn't fail actually; a quick check confirmed that it could be fixed by changing the above lines to the following:

        try:                                                                                                                       
            win32.SetNamedPipeHandleState(                                                                                         
                h2, win32.PIPE_READMODE_MESSAGE, None, None                                                                        
                )                                                                                                                  
        except WindowsError, e:                                                                                                    
(win32)                                                                                                       
            if e.args[0] != 0: # 0 is error code for SUCCESS                                                                       
                raise
msg108826 - (view) Author: Alexander Myodov (amyodov) Date: 2010-06-28 13:00
Sorry for formatting above, a copypaste issue.

The lines 202-204:
        win32.SetNamedPipeHandleState(
            h2, win32.PIPE_READMODE_MESSAGE, None, None
            )

The change that fixes the problem (at least for me):
        try:
            win32.SetNamedPipeHandleState(
                h2, win32.PIPE_READMODE_MESSAGE, None, None
                )
        except WindowsError, e:
            if e.args[0] != 0: # 0 is error code for SUCCESS
                raise
msg122005 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-11-21 22:32
Can you provide a test case for this?
msg137760 - (view) Author: Alexander Myodov (amyodov) Date: 2011-06-06 17:44
Sorry for being a little bit slow to respond...
No I was not able to come up with a testcase that could generate this problem in a reproducible way on any Windows box I had. This problem sometimes occured on various OS versions, being probably a Windows oof configuration problem rather than the problem of the Python code itself. Nevertheless, changing it as I described above didn't cause any adverse side effects, at least for me.
History
Date User Action Args
2011-06-06 17:44:11amyodovsetmessages: + msg137760
2010-11-21 22:32:32brian.curtinsetnosy: + asksol, brian.curtin

messages: + msg122005
stage: test needed
2010-06-28 13:55:15r.david.murraysetnosy: + jnoller
2010-06-28 13:00:32amyodovsetmessages: + msg108826
title: multiprocessing/win32: -> multiprocessing/win32: WindowsError: [Error 0] Success on Pipe()
2010-06-28 12:54:58amyodovcreate