4

According to the example from:

How can I start X11 only for a single application?

I'm running python script that shows Tkinter frame by invoking:

startx ./script.py

... when the script is done, it exits with:

root.destroy() # Tk() from Tkinter
sys.exit(0)

... however X server seems still to be running (blank screen is displayed and I have to use Ctrl+C to get access to the console back).

How can i make xserver stopped immediatelly when following application exits?

EDIT: I've noticed that if i didn't use MyThread (but e.g. timer handler method), closing X windows session works fine. Also this script finishes properly when run (tested) on Windows.

Code with issue:

#!/usr/bin/env python

import sys
import threading
import time
from Tkinter import Tk, Frame, BOTH

SCREEN_RES = "1024x600"
DELAY = 1000
TK_ROOT = Tk()


class MyThread(threading.Thread):

    def run(self):
        try:
            print "Entering MyThread..."
            time.sleep(3)

            print "Exiting MyThread..."    
            TK_ROOT.destroy()
            sys.exit(0)

        except KeyboardInterrupt:
            exit()


# noinspection PyAttributeOutsideInit
class SysInfo(Frame):
    mt = MyThread()

    def __init__(self, parent):
        Frame.__init__(self, parent, background="gray")

        self.parent = parent
        self.init_ui()

        self.after(DELAY, self.on_timer)
        self.mt.start()

    def init_ui(self):
        self.parent.title("SomeFrame")
        self.pack(fill=BOTH, expand=True)

    def on_timer(self):
        print("Timer fired.")
        self.after(DELAY, self.on_timer)


def main():
    TK_ROOT.geometry("%s+0+0" % SCREEN_RES)

    SysInfo(TK_ROOT)
    TK_ROOT.mainloop()


main()
1

According to the flipping manual, which I hope you have found the chance to read, normally startx(1) will look in order for ~/.xinitrc then in the xinit library directory for a system default xinitrc script to run - but as you have provided command line client arguments instead (./script.py) that is used instead. You might find it instructive to look for the system wide script for clues as to how things are normally done.

I think you may get somewhere with further arguments after a -- on the line that you use, arguments after that symbol are server arguments, one of which may be relevant is -terminate which according to the X server command line help:

causes the server to terminate at server reset, instead of continuing to run. This overrides a previous -noreset command line option.

Perhaps this can give some possible pointers...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.