I create a screen in linux and run a python script in that screen.
After running 1 month 24/7, when I check the progress of the python script, the script stops running without being killed or terminated the script. May I know how to troubleshoot why the script stop running in the linux's screen?
Thanks inadvance.
Related
Unfortunately, I can't seem to use Windows Task Scheduler as I don't have admin rights on my work computer, and when I sign in as admin to run tasks the Python script doesn't run. Because of this, the only alternative I've found is creating a bash script that will run my .py file and adding that to my programs that run on startup.
This seems to work fine whenever I restart my computer, but I notice that if I leave my computer on overnight the batch script will close and my Python script won't run. I've checked the log files for any errors and there don't seem to be any issues in the script, it just seems that the cmd prompt screen closes.
Here is what I put in my .bat file:
"C:\Python\Python37-32\python.exe" "T:\service.py" > T:\output.log 2>&1
cmd /k
Just trying to figure out- why is this happening? And is there any way I can just keep this script running as long as my computer is on?
You could attempt to create a Windows Service with PowerShell. Just have it automatically recover when it's terminated. See this as a reference.
https://github.com/yaplex/CodeSamples/blob/092159a847e330778494ea7b69ee84d120db7e36/PowerShell/Install-Windows-Service.ps1
Then you can monitor trends with Event Viewer as to why and when it's terminated.
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.
I am trying out a python tutorial on the raspberry pi, and have found that more often than not, CTRL+C, or selecting shell > interrupt execution from the menu, will not stop a running script.
I do get a warning when I close the entire window: your program is still running, do you want to kill it?, but it looks like the script even runs when the window is closed, because the cursor changes into an hourglass for all python windows.
How can I force stop a python script on raspberry?
Try executing the command ps -ax | grep python in command line to find the process id of your script. Once you find that, kill that process using this command sudo kill <process_id>
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.
I have Python script running as service(24/7). This script is executed by LaunchDaemon on start. I would like to implement GUI for this script so I could check progress. How can I recognize my script is running and just open thread with GUI when I start that script again?
Thank You
You could look at Tkinter to run at start up? Using a simple if running display "running" else display "error"