6

I'm running Python 3.3 on Windows 7. I have a script that succeeds when I call it like this:

c:\python33\python.exe my_script.py

But fails when I call it like this:

c:\python33\pythonw.exe my_script.py

I want to be launching it regularly using pythonw, since it's supposed to run once every hour and I don't want to see the ugly console window every time it's launched.

(I know the script fails under pythonw because (a.) it exits immediately, when it should take about two minutes, and (b.) it's supposed to send an email and it doesn't.)

How do I even debug it? Since pythonw doesn't show any output, I have no idea what to do.

Ram Rachum
  • 84,019
  • 84
  • 236
  • 374

1 Answers1

3

You could wrap your top-level code in a try-except handler that logs the exception:

import logging

logging.basicConfig(filename=r'C:\TEMP\debug.log', level=logging.DEBUG)
try:
    # top-level code
except:
    logging.exception('Danger, Robinson!')
    raise

You can add other logging calls, you could create a logging object to give you more fine-grained control over the configuration, etc, but as a first step that's what I'd do.

If the program still insta-exits, start bisecting. Remove half the code, compare that removing the other half (allowing for dependencies). If one half breaks and the other half works (within the constraints of half the code missing) then you know where to continue your search.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343