How can I debug a script in real-time?
Run blender straight from the command line...then watch the console for the errors. If blender quits, the info will be printed out. Also, add printouts or setup a python logger to "view the contents of variables."

I can't really think of any other ways to help other than these suggestions without seeing the code (or even a description of what happens when the "bug" occurs).