python script via windows 7 scheduler still running - python

I'm a noobie to python and have over the past few days tested and created a .PY file that runs perfectly from the command prompt either with the D:\Python34 or just as
Its pretty basic. Gets info from web and places it in a spreadsheet - I import requests, BeautifulSoup and openpyxl. The last statement is to save the workbook. I'm figuring that Python closes itself as does the workbook.
I wish to run it daily. So I used the Windows Task Scheduler on my Windows 7 Ultimate. I have it running only when I am logged in.
I have tried the following:
1) using python directly with complete paths
2) using only the full path and the
3) using a batch file that does #1 above and has an EXIT
4) using a batch file that does #2 above and has an EXIT
When running the batch from the command file OR Task Scheduler, the command window opens, it does its thing and the command window closes.
The problem is when I run it via the Task Scheduler in any of the above ways, it does its thing, but continues to say "RUNNING" in the scheduler.
I have tried to run the Windows Process Monitor using some filters I found on the web, however nothing shows up.
Extremely frustrating --Any suggestions would be appreciated.
Jerry

While I had the Task Scheduler open, the screen was showing "running". After I closed the screen and let it run the next day, everything worked fine. It must be something to do with the refresh on the task scheduler.
So my solution was to close the Task Scheduler and let it run as scheduled.

Related

How to Resume Python Script After System Reboot?

I'm still new to writing scripts with Python and would really appreciate some guidance.
I'm wondering how to continue executing my Python script from where it left off after a system restart.
The script essentially alternates between restarting and executing a task for example: restart the system, open an application and execute a task, restart the system, open another application and execute another task, etc...
But the issue is that once the system restarts and logs back in, all applications shut down including the terminal so the script stops running and never executes the following task. The program shuts down early without an error so the logs are not really of much use. Is there any way to reopen the script and continue from where it left off or prevent applications from being closed during a reboot ? Any guidance on the issue would be appreciated.
Thanks!
Also, I'm using a Mac running High Sierra for reference.
You could write your current progress to a file just before you reboot and read said file on Programm start.
About the automatic restart of the script after reboot: you could have the script to put itself in the Autostart of your system and after everything is done remove itself from it.

Issues launching a python script with Windows 7 Task Scheduler

I have a python script that incorporates subprocesses. I want it to run at a given time, so I set up a task to launch the .py script. However, it does not run...I viewed the history of the event and it appears to have "started" and closed all at 3:30:00 pm. So nothing really ever happened. I have also tried starting it in a batch file, that does not work with the task scheduler either. However, both the standalone script and the batch file work independently of the task scheduler just fine. Has anyone seen this or have any idea what I need to do to fix this issue?

Console window closes abruptly while using windows task schedular to run Python script

I have written some Python code to automate a task. Then I scheduled the Python script to execute twice a week using windows task scheduler. The task runs but there are two issues.
The console prints some error. It is strange because when I run the script manually after opening command prompt everything works as expected. This is what I do manually.
cd directory
directory>script.py
Inside the task scheduler I have directly specified the location of the script to run as C:\full\path\to\script.py
Second issue is that I can't even diagnose the error because the console closes as soon as it executes the script. This is despite the fact that I have added a dummy input command at the end of script like this:
All my Python code
input('Press any key to exit')
I also tried to keep the console open by using time.sleep(60) after importing the time module.
Can anyone tell me how can I keep the console open. Let me repeat that I am running the script using windows task scheduler. Running the script manually generates no error.
Thanks.

Windows Task Scheduler running Python script: how to prevent taskeng.exe pop-up?

Windows 7 Task Scheduler is running my Python script every 15 minutes. Command line is something like c:\Python\python.exe c:\mypath\myscript.py. It all works well, script is called every 15 minues, etc.
However, the task scheduler pops up a huge console window titled taskeng.exe every time, blocking the view for a few seconds until the script exits.
Is there a way to prevent the pop-up?
Simply save your script with .pyw extension.
As far as I know, .pyw extension is the same as .py, only difference is that .pyw was implemented for GUI programs and therefore console window is not opened.
If there is more to it than this I wouldn't know, perhaps somebody more informed can edit this post or provide their own answer.
This helps me:
In the “General” tab, under the “Security options” section, select the Run whether user is logged on or not option. (This is the option that will make the command window not to appear when the task runs automatically.)
Clear the Do not store password option. (This is an optional step, but if the task isn’t working, check this option and supply the appropriate credentials to run the task.)

Python cron job under windows7

I have created a simple cron job under windows to run a very simple python scrape:
scrape webpage
store data into csv file
close file
Cron job under Windows worked fine-without any probs. All of sudden, that cron job stopped working, my output file is not getting updated. When I run the scrape manually (double click on python file or via python IDE) I would typically get my debug output "everything ok" in a windows dialog window and the target file gets updated. During the cron job I can see that debug output window popping up and printing the same "everything ok" debug, but the file is just not getting updated.
I tried rebooting my machine, close/open all program. Created a new task in the scheduler, it still wouldn't work. Any suggestions?
Thanks
Peter
After playing around with all potential settings in windows and many wasted hours I found a workaround.
My initial setup in the task manager was calling the python.exe and my python.py file was passed as an argument. Just as described here: http://blogs.esri.com/esri/arcgis/2013/07/30/scheduling-a-scrip/. The difference at the end that made my cron job work again was that I deleted passing the python file as an argument and now calling python file directly. Not sure why the initial setup stopped working - but this has helped. Hope you don't get into the same time wasting situation.

Categories