What code can be used to close a program running on RPI3?
I am running a
smart magic mirror using my Raspberry Pi, and I want to then close it. How can I?
It depends how you are accessing the Pi. If you are running it headless (without a separate monitor) then you need to use ssh to log in from another computer (ssh username#ip-address in the terminal window). You can then use other methods such as process killing to force the program to stop running on the Pi.
Alternatively, if you have access to the where you started the program on your Pi (maybe a window, or a terminal window where the Pi is running your mirror program, then you could exit or use a common interrupt such as Ctrl+C.
Related
I've created a simple program in python3 with selenium to monitor a website. The program works as intended when I run it on my own computer, but as I need to keep it running 24/7, I've put it on a droplet from digital ocean. The program works when I am connected to via ssh, but from the log file I can tell that the program stops as soon as I close the connection. I'm guessing it has something that the problem is that the program is running on the same thread as the connection. My question is: How do I make sure the program runs in the background so it will keep running even after I close the coonection to the droplet?
Try using screen.
It allows you to run programs in separate windows so they run completely independent from each other, and also should keep your program running while not connected.
More info about screen: https://www.gnu.org/software/screen/
i got a python script to collect data from a few connected sensors. This script runs in background from starting the PI. The script is working fine but irregular it fells in 'Sl' state. If i restart the PI it works again for a few days, but then it happens again.
Is there a way to monitor the state of the script (kill it and start it again if this happens) or any idea why this happen?
You have a few options (somewhat related):
Run your script as per normal, but have another script (bash works good) that checks for the state of your script. If it's stalled, kill it, and restart. This second script can be called from a regular cron job.
Change your python script into a linux service (see here for an example), and either monitor this service with a second script (similar to 1), OR, do a service restart at regular intervals with a cron job.
I am making an image processing solution where the Raspberry Pi processes the image using a python script, and sends the result to an Arduino board. I want to keep this system always running, as Raspberry Pi has a Linux kernel, so is there any way to keep the python script on the pi always running?
It's not clear if the images will be stored on a folder or how your script will receive the images, but here are 2 options:
Setup a cron job to run your script every X seconds/minutes, process all images available and send them to the arduino board
Run your script in the background as a service, there are some cool instructions on the following link:
http://blog.scphillips.com/posts/2013/07/getting-a-python-script-to-run-in-the-background-as-a-service-on-boot/
If you keep terminal running forever, then you can simply use python's While condition
while True:
*do some thing*
and keep the program running as long as u need you can also use time module if you want it to sleep for few sec or mins
I have connected an LCD to my Rapsberry Pi which is acting as a frame buffer device (booting and desktop visible when running Raspbian). To control the LCD I use Python and Pygame, which works perfectly.
But I would like to auto start this application.
The only way I could which resulted in the Python application taking control over the LCD is by using LXDE autostart. But the application then runs twice! My guess this is due to the fact that I also run vnc, so I have two desktops which both autostart the application.
Is there any way to resolve this?
Here's a short description of what I have:
I have to raspberry pi's in a local net work. I one of them I have a .py script named watchdog.py that starts a stream and then uses a sshpass command to the other pi to display the video stream.It also has some signaling LEDs a some push buttons for control
the problem is:
If I open a terminal and run the watchdog.py script in the GUI everything runs as it should be. So I thought of running it as a service as boot and installed upstart and made it run as a service (successfully I think). The thing is. If I boot the pi and then press the button to start the streams,they wont play on the other Pi, the LEDs ligh up and all the buttons work. And even the CPU load behaves the same way, but i still don't video nor audio. I have thought of trying automatically open a terminal (LXterminal) widow and run the python scrip on that window. but I didn't want the streaming raspberry pi also booting into gui (tough I guess I would mind if that makes the whole thing work).This little thing i making the whole project useless.
What are you using to play the streams? Depending on how you boot up the second Raspberry it might not have started some daemons for audio/video playback?!
You should (if you're not already doing) write a log (import logging ;)) and write a logfile which you can track for errors.
answer moved from OP's question itself:
I found a way that seems to work so far. instead of running the python script as a service I tried running it as cron job at reboot, and it worked. now it all works straight from reboot and I have Audio and video.