Keyboard interrupt handling response under IDLE

Sam Schulenburg samschul at ix.netcom.com
Tue Apr 13 19:00:41 EDT 1999


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







More information about the Python-list mailing list