0

I have a python script that checks the temperature every 24 hours, is there a way to leave it running if I shut the computer down/log off.

elmuscovado
  • 84
  • 2
  • 6
  • 11
  • 5
    Um... No. If the computer is shut down, how do you expect the Python code to run? There has to be a computer running in order to run code on it. Think about it. *I want to heat my coffee in my microwave, but I unplugged it. Can I still heat my coffee using it?* No, not without plugging it back in. – Ken White Apr 05 '17 at 17:32
  • 1
    You don't provide very much information at all here. Shutting down the computer and logging off are two completely different actions. If the computer is off, then no, nothing can run. You might be asking if you can shutdown the computer and when you turn it back on to have your script run. In that case, just schedule the script (cron or windows tasks). If you want to log off the computer and have something run, then it needs to run as a service and/or daemon. This too could be accomplished with cron or windows tasks. Please provide more information. – Joshua Schaeffer Apr 05 '17 at 17:32

4 Answers4

2

Shutdown - no.
Logoff - potentially, yes.

If you want to the script to automatically start when you turn the computer back on, then you can add the script to your startup folder (Windows) or schedule the script (Windows tasks, cron job, systemd timer).

If you really want a temperature tracker that is permanently available, you can use a low-power solution like the Raspberry Pi rather than leaving your pc on.

Alan
  • 2,088
  • 2
  • 9
  • 20
  • What you mention sounds good, please could explain in more detail (I am using windows but am quite new to it as until recently i used mac) – elmuscovado Apr 05 '17 at 17:38
  • If you add the script to "C:\Users\{username}\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\", it will start when that user logs in; add to "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\" for it to fire up automatically if any user logs in. – Alan Apr 05 '17 at 22:02
1

The best way to accomplish this is to have your program run on some type of server that your computer can connect to. A server could be anything from a raspberry pi to an old disused computer or a web server or cloud server. You would have to build a program that can be accessed from your computer, and depending on the server and you would access it in a lot of different ways depending the way you build your program and your server.

Doing things this way means your script will always be able to check the temperature because it will be running on a system that stays on.

EJGannon
  • 13
  • 4
0

Scripts are unable to run while your computer is powered off. What operating system are you running? How are you collecting the temperature? It is hard to give much more help without this information.

One thing I might suggest is powering on the system remotely at a scheduled time, using another networked machine.

0

You can take a look at the following pages http://www.wikihow.com/Automatically-Turn-on-a-Computer-at-a-Specified-Time

http://lifehacker.com/5831504/how-can-i-start-and-shut-down-my-computer-automatically-every-morning

Additionally once it turn on, you can perform a cronjob, for execute your python code by a console command >> python yourfile.py . What is the Windows version of cron?

Community
  • 1
  • 1
John
  • 33
  • 4