This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author anselm.kruis
Recipients Ramchandra Apte, amaury.forgeotdarc, anselm.kruis, kristjan.jonsson, pitrou
Date 2013-05-10.12:05:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1368187550.13.0.696422235587.issue5773@psf.upfronthosting.co.za>
In-reply-to
Content
Hi,

I was faced with a very similar problem also caused by an invalid file descriptor.

My solution is to set an invalid parameter handler, that does nothing. This effectively disables Dr. Watson. Perhaps this is a suitable solution for other users too. And it does not require a patch.

def set_invalid_parameter_handler(flag):
    """
    Set the MSVCRT invalid parameter handler.
    
    If flag is True, this function sets an invalid parameter handler,
    that does nothing. This effectively disables Dr. Watson.
    If flag is an integer number, it must be the address of an 
    invalid parameter handler function. 
    If flag is None, this function removes the invalid parameter
    handler. This effectively enables Dr. Watson.
    
    The return value is the address of the current handler or None,
    if no handler is installed.
    
    Example::
    
        old = set_invalid_parameter_handler(True)
        try:
            do_something_nasty
        finally:
            set_invalid_parameter_handler(old)
     
    """
    try:
        # get the msvcrt library
        import ctypes.util
        libc = ctypes.util.find_msvcrt()
        if not libc:
            # probably not windows
            return None
        libc = getattr(ctypes.cdll, libc)
        siph = libc._set_invalid_parameter_handler
        siph.restype = ctypes.c_void_p
        siph.argtypes = [ ctypes.c_void_p ]
        # now we need a suitable handler. 
        # The handler must simply return without performing any actions.
        # Of course there is none.
        # But if we look at the calling convention (cdecl), and 
        # at the fact, that we don't need the argument values
        # we find, that we can call any function, as long as the function 
        # does not harm. A suitable function is "int abs(abs)".
        null_handler = libc.abs
    except Exception:
        # probably not the correct windows version 
        return None
    if flag is True:
        flag = null_handler
    return siph(flag)
History
Date User Action Args
2013-05-10 12:05:50anselm.kruissetrecipients: + anselm.kruis, amaury.forgeotdarc, pitrou, kristjan.jonsson, Ramchandra Apte
2013-05-10 12:05:50anselm.kruissetmessageid: <1368187550.13.0.696422235587.issue5773@psf.upfronthosting.co.za>
2013-05-10 12:05:50anselm.kruislinkissue5773 messages
2013-05-10 12:05:49anselm.kruiscreate