Creating a Scheduled task in Tkinter on Unix - python

Through an application I have made with Tkinter, I'm trying to add a command to run a script every week. When the program is closed the command should be in forever place.
I've sifted through the documentation on cron, but there doesn't seem to be a way to edit the crontab without using the shell. Also I've looked through the 'at' command, but that only seems to run once.
My question is - How can one create a weekly recurring task by issuing a single command in Python on Unix?
If not with only 1 command, can I use multiple?

In most modern Linux distros like Debian or Ubuntu, you can add an executable file (like a shell script or a symlink to one) into /etc/cron.weekly and it will be automatically run once a week for you. This is using the anacron command, which is fairly common these days.

Related

Python Script Windows Task Scheduler

This is my first time to schedule a python script.
My goal is to schedule my python script to run every 10 min.
MAIN.PY
from scrapy import cmdline
cmdline.execute("scrapy crawl news".split())
I created a task in windows task scheduler, but my script is not running somehow( I know the script is working since i can run it manually ). I been trying to solve this issue for hours without any luck.
First I select my python path, then I select the filepath for the project and choose the .py I want to run.
example here
Then I choose to trigger every 10 min.
After doing the steps described above, nothing happens.
Hope you can help me with a solution to my problem.
Not sure that it will fit in your case, but I think it might. Please, check out this topic.
How do you run a Python script as a service in Windows?
Maybe you can run your script as a service and add a simple timer inside the script that launches your routine every 10 minutes from the inside.
Alternative solution that a colleague of mine is using is packing the python script inside an executable by using fbs or pyinstaller and adding it into the task scheduler.
it might be the environment problem.The windows task scheduler is running in C:\Windows\System32 by default,so if your some argument is not absolute path or will changed with the environment,it will get wrong result.i suggest u use some logging way to record your program's running status and result so u can debug where went wrong

How to restart python script inside bash script every x hours?

I have a quite simple question about starting and restarting python scripts inside an bash script. I hope it's not an duplicate but I didn't find a similiar question. I'm using a bash script which starts a couple of python scripts every time I create a docker container, but It should be probabaly the same on all linux based machines. It's simple as: python3 /mnt/device/script.py &
Now the script will keep running and measure the brightness until the container is stopped. Now I figured out that there are some problems with the sensor library which are brightly discussed on github and still not solved which causes the script to stop every couple of hours. For me It would be enough to have just some command which restarts my script which is running in the background every x hours to avoid that error. So what I'm looking for ist some command which will be like the follwing: python3 for hour=1 /mnt/device/script.py restart &
Thanks in advance!
You can use the Bash timeout command to send a signal to kill the Python script.
restart=""
while true; do
timeout 3600 python3 /mnt/device/script.py $restart
restart="restart"
done &
I'm guessing you don't really need this to run in the background (so maybe take out the &) and that you literally want restart to be passed as an argument after the first time.

Running a Python Script in the background from Startup [duplicate]

This question already has an answer here:
Python script start on boot
(1 answer)
Closed 3 years ago.
I want to monitor a file in a specific location and check it for updates, which upon being updated launches certain actions via a python script.
Ideally, this program would always be running in the background and would automatically start with the computer so that the user does not have to mess with starting/stopping it.
I have researched the topic some and have found daemon and similar tools, but I do not understand how they work and they look far more complex then what I need. Also, many of the examples that I am looking at use Ubuntu OS and I will be using Windows.
Are there any python modules that exist to do this already or any direction you can point me to get started? I apologize if this question has been answered already, however I have not found it in my research.
I plan on editing this post to include code that performs this action, however I currently do not know where to start.
On Windows you could create a batch script and schedule it using the Windows Task Scheduler to run as a process on boot.
You can trigger the Python script to run inside the batch file,
python file.py
Alternatively, if you're using something like Anaconda as your environment manager; you could write a batch file to activate Anaconda using the activate.bat contained in the Scripts folder of your Anaconda installation path and then follow the usual calling steps.

Is there a python module for the Linux "at" task scheduler

Lest I reinvent the wheel .... again:
Is there a python interface, API or module for the standard linux "at" task scheduler? I have tried searching the internet but searching for the word "at" is a tad bit useless :-)
My intention is to have a python script process same data and construct a shell file. Then use a subprocess call to have "at" schedule the job file for a specific date and time. I will have a similar function using "Schtasks.exe" if python detects it is running on windows. Lastly the python script exits ... leaving system scheduler the responsibility of running the job file.
update 1 July 2019:
Found an interesting "at" quirk.
The file called on the "at" command line (i.e. the script or shell file) does not need to be marked as "executable" in order to be run by "at".
For the record: I am running Linux Mint 19.1
You can achieve this with different approach:
Write your python script.
Call this script with a bash file.
Schedule bash file with a crontab task.

Python Shell memory management for always running script

I have written a python (python version is 3) script that runs 24/7. The way I run my script in my Windows machine is the following. I right click on the .py file, then click on "Edit with IDLE" and then "Run". The script has no issue but, due to the many instructions printed in the python shell (I use a logger), after a couple of days this python shell gets very heavy. My newbie question is the following. Is there to limit the number of rows temporarily saved in the python shell to a specific number? Or perhaps somebody has a better suggestion to run this constantly running script that prints a lot of the script steps in the shell? Please, notice how I'm not asking how to run a script 24/7, it's my understanding the best way to do it is though a VPS. My problem is that the data saved in the displayed python shell gets bigger and bigger every day, so I only wonder how to limit the data temporarily displayed/saved in it. Thanks

Categories