I've got this python script that opens up a VNC session through a graphical window. It sits there blocking waiting for a particular message to come in and then spawns the graphical window successfully when ran from the command prompt.
But if I place this in an Upstart .conf file so I can use it as a background service, I can see that my program receives the message to pop up a window but it does not display a graphical window.
...
exec /usr/local/bin/vncscript.py # does not display window
...
How would I go about displaying a graphical window using Upstart?
Ended up going with the solution from by setting up a .desktop file:
https://askubuntu.com/questions/107187/how-to-launch-gui-app-with-upstart-script
Initially, I started by a
export DISPLAY=0.0
...and it worked. I could then control it as a service. But as soon as I restarted the computer, it would not work as expected. Could not even stop the service after starting it. I'm not sure why it worked in the first place.
Related
I am creating a GUI interface that will be using a 7" touch display with a raspberry pi 3. I want the GUI to take the place of the desktop, I do not want it displayed in a window on the desktop. any thoughts on how to do that. I have read the raspberry pi documentation to edit the rc.local script to start the application at login, but I can not figure out how to set up the python GUI with out creating a window
Your pi boots up and displays a console - just text - by running a program (getty). Then you run another application called a graphical display manager which then runs a window manager. On a pi it is usually gnome but there are many others,.. this window manager is what displays your GUI window. What you want is obviously possible, it is just that it is non-trivial to do. What you are talking about is either kiosk-mode application still running 'on the desktop' as you say but which obscures the desktop completely and does not allow you to switch or de-focus or an even more complicated JeOS like Kodi/XBMC bare metal installation running without your current window manager. Your python would have to do the job of the display manager and the window manager and it would be very, very slow.
Use a really light window manager and go kiosk mode. Or you could go with text! There are libraries eg ncurses but I'm not sure how that would work with your touch screen display.
1.
Disable graphical interface i.e. stop the desktop manager from running.
On Raspbian you can use raspiconfig to do it.
2.
Set up autologin into bash
3.
Block startx from automatically running desktop manager
4.
Add your app to be started from .bash_rc when autologin is performed.
To setup autologin first create a script called autologin in /bin directory that does:
#! /bin/bash
/bin/login -f pi
Note: pi is an user on raspbian that won't ask for password when sudo-ing.
To use the created script edit /etc/inittab:
Scroll down to where terminals are assigned and change tty1's line to be:
1:2345:respawn:/sbin/getty -n -l /bin/autologin 38400 tty1
Take care that ids are matching old tty1 settings.
Then in the user's home directory (/home/pi) add (if it's not already there) a file named ".xinitrc" containing just:
#! /bin/bash
cat
This will prevent X server from invoking desktop manager when started.
Now add in /home/pi's .bashrc your app or better a script that will run your app (at the end):
export DISPLAY=:0
/home/pi/Desktop/appstart &
startx
And appstart is:
#! /bin/bash
# Wait a second for X server to start:
sleep 1
# Now X is running and we have to switch into video terminal using chvt (change virtual terminal) command
# Graphic terminal is on Raspbian tty7
sudo chvt 7
# Start the app:
python /home/pi/Desktop/myapp/myapp.py
After all this is set up what will hapen is the following:
1.
You run Raspberry Pi and it autologins into user pi
2.
When Bash logs in it executes /home/pi/.bashrc
3.
.bashrc sets $DISPLAY variable because there are no X displays yet, runs starting script as a background job and starts X server.
4.
X server won't enter desktop manager because /home/.xinitrc will stop it step short of it.
5.
Starting script sleeps for a second to ensure that X is running and able to send graphics to tty7, switches to tty7 so that user doesn't have to do it manually, and then runs your application which will show up.
If your app is not graphical you will see only one big nothing. :D
Problems here are that you definitely should create an user just for this stuff. If your app crashes or user switches to tty1 and terminates X there he/she is in bash, logged in.
Depends on what level of security you need. You can do a lot of things to prevent abuse. For example, use fcntl to change mode tty1 is in so that it cannot receive key input any longer.
Or use some other tricks, or rearange this procedure somewhat, or ensure that tty1 runs everything in jobs with nohup, then logs out etc, etc.
I have an external server that I can SSH into. It runs bots on reddit.
Whenever I close the terminal window the bot is running in, the process stops, which means the bot stops as well.
I've tried using
nohup python mybot.py
but it doesn't work - when I close the window and check the processes (ps -e), python does not show up. Are there any alternatives to nohup? Ideally, that print the output to the terminal, instead of an external file.
Have you considered using tmux/screen? They have lots of features and can help you detach a terminal and re-attach to it at a later date without disrupting the running process.
I have an python 2.7 application that I would like to move from the CMD window to the system/notification tray (Windows 7). The python script currently listens for particular TCP messages, and upon receipt, logs them to a file.
I have recently found the following system tray code, from another question answered here:
systrayicon
I've been able to run the systrayicon demo correctly by creating the SysTrayIcon.py module. My problem is, when I try to run my TCP application alongside the systrayicon (with some of the demo code intact), it only runs my application, or the system tray application, not both. More specifically, if I list my app's main(sys.argv) before the systrayicon(), it only runs my app without the tray icon. If I have the systrayicon listed before my app, it runs the system tray demo, until I select "Quit", and it then runs my app.
I am able to get my TCP app to run correctly if I plug it into one of the menu selection functions, for example:
def hello(sysTrayIcon):
main(sys.argv)
But I'd like my app to begin listening when the application is opened, without selecting something from the menu to initiate it.
This is likely a very basic problem, and maybe worded poorly, my apologies.
I think the easiest way for you to accomplish this would be to just wrap your script with a small piece of GUI code using Tkinter or wxPython. Then it can reside in the tray. You will probably need to run your script in a thread as it sounds like a long running process that would block the toolkit's main loop. You might need to add some code to the threading code that allows you to kill your script when the GUI exits, but other than that, it should be pretty easy.
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.
In Gnome, whenever an application is started, the mouse cursor changes from normal to an activity indicator (a spinning wheel type thing on Ubuntu). Is there any way to inform Gnome (through some system call) when the application has finished launching so that the mouse cursor returns to normal without waiting for the usual timeout of 30 seconds to occur.
I have a program in Pythong using GTK+ that is showing the icon even after launching, so what system call do I make?
Normally it happens automatically when you open the application's window.
It may be that the application's launcher just calls an already running instance, in that case it won't be automatically detected. The call you need then is this:
import gtk
gtk.gdk.notify_startup_complete()
Your application can opt out of startup notification by adding
StartupNotify=false
to your application's .desktop file.
Of course, it is friendlier to leave it enabled and participate in startup notification.
I had a similar issue with an application I wrote. I was launching the application through a shell script containing the line
python /path/to/application.py
This launched the application as I expected, but the startup notification did not stop.
It worked correctly once I changed the content of my script to this:
exec "/usr/bin/python" "/path/to/application.py"
Obviously the latter one seems to be the correct way to launch the application, though I don't have enough insight to tell why.
This normally happens automatically when calling the gtk.main() function