From: samschul at ix.netcom.com (Sam Schulenburg)
Date: Tue, 13 Apr 1999 16:00:41 -0700
Subject: Keyboard interrupt handling response under IDLE
Message-ID: <7f0iad$nqj@dfw-ixnews4.ix.netcom.com>
Content-Length: 2742
X-UID: 789                                                  

Keyboard interrupt handling response under IDLE

The following function performs a call to a DLL that handles issuing
commands to an external SCSI hard disk drive.

def test():
      while(1):
          try:
             io6(0x12,0x00,0x00,0x00,0xff,0x00)
             print '*',
          except KeyboardInterrupt:
             key = raw_input('Key board interrupt detected: do you want to
continue Y/N ')
             if(upper(key) != 'Y'):
               break

The io6(0x12,0x00,0x00,0x00,0xff,0x00) function resides within the DLL and
will report all errors back to Python via
this function call:

static void vLogP(UCHAR *ucMsgStr,UCHAR ucIndex)
{
   UCHAR ucPyString[200];
   if( iERRORMSG == 1)
    {

      wsprintf(ucPyString,"sys.stderr.write(\'%s\')",ucMsgStr);
      PyRun_SimpleString(ucPyString);
      wsprintf(ucPyString,"print \"\"");
      PyRun_SimpleString(ucPyString);
    }
   else
    {
      wsprintf(ucPyString,"print \"%s\"",ucMsgStr);
      PyRun_SimpleString(ucPyString);
    }
};


The problem occurrs when the function within the DLL has an error and the
reported error occurrs continously.
What appears to happen is that the IDLE enviroment detects the error as
shown below but does not always
throw the exception


*Drive is not available for testing:
Traceback (innermost last):
  File "<string>", line 1, in ?
  File "D:\Python152\Tools\idle\PyShell.py", line 598, in write
    self.shell.write(s, self.tags)
  File "D:\Python152\Tools\idle\PyShell.py", line 589, in write
    raise KeyboardInterrupt
# Detected the exception but continued with the main loop
KeyboardInterrupt
*Drive is not available for testing:
*Drive is not available for testing:
Traceback (innermost last):
  File "<string>", line 1, in ?
  File "D:\Python152\Tools\idle\PyShell.py", line 598, in write
    self.shell.write(s, self.tags)
  File "D:\Python152\Tools\idle\PyShell.py", line 589, in write
    raise KeyboardInterrupt
# Detected the exception but continued with the main loop
KeyboardInterrupt
*Drive is not available for testing:
*Drive is not available for testing:
*Drive is not available for testing:
*Drive is not available for testing:
*Drive is not available for testing:
*Drive is not available for testing:
Traceback (innermost last):
  File "<string>", line 1, in ?
  File "D:\Python152\Tools\idle\PyShell.py", line 598, in write
    self.shell.write(s, self.tags)
  File "D:\Python152\Tools\idle\PyShell.py", line 589, in write
    raise KeyboardInterrupt
KeyboardInterrupt
# Detected the exception but continued with the main loop
*Drive is not available for testing:
*Drive is not available for testing:
*
Key board interrupt detected: do you want to continue Y/N n        # Finally
caught the exception







