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.
python.exe is associated with . py files and opens and runs in a terminal window. pythonw.exe is associated with . pyw files and does not open the terminal.
Ctrl + C on Windows can be used to terminate Python scripts and Ctrl + Z on Unix will suspend (freeze) the execution of Python scripts. If you press CTRL + C while a script is running in the console, the script ends and raises an exception.
pythonw.exe should be in the same directory as python.exe . For me (running Python 3.8) that is C:\Program Files\Python38 .
pythonw.exe is a GUI app for launching GUI/no-UI-at-all scripts. NO console window is opened. Execution is asynchronous: When invoked from a console window, the script is merely launched and the prompt returns right away, whether the script is still running or not.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With