Python script failing under pythonw
Asked Answered
S

1

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.

Saddlebag answered 21/11, 2015 at 14:11 Comment(3)
pythonw.exe or python.exe?Emelyemelyne
@vaultah: yes, I'm sure the OP knows the difference. Why that link, exactly?Rosewater
@Emelyemelyne Not seeing anything helpful there.Saddlebag
R
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.

Rosewater answered 21/11, 2015 at 14:15 Comment(1)
@J.F.Sebastian: I had a as exc target there at first until I edited out the need for one.Rosewater

© 2022 - 2024 — McMap. All rights reserved.