# Buggy code
def error_and_exit(title, main_text):
    """
    Show a pop-up window and sys.exit() out of Python.

    :param title: the short error description
    :param main_text: the long error description
    """
    # NOTE: We don't want to load all of these imports normally.
    #       Otherwise we will have these unused GUI modules loaded in the main process.
    from Tkinter import Tk, Canvas, DISABLED, INSERT, Label, Text, WORD

    root = Tk()
    root.wm_title("Tribler: Critical Error!")
    root.wm_minsize(500, 300)
    root.wm_maxsize(500, 300)
    root.configure(background="#535252")

    Canvas(
        root,
        width=500,
        height=50,
        bd=0,
        highlightthickness=0,
        relief="ridge",
        background="#535252",
    ).pack()
    pane = Canvas(
        root,
        width=400,
        height=200,
        bd=0,
        highlightthickness=0,
        relief="ridge",
        background="#333333",
    )
    Canvas(
        pane,
        width=400,
        height=20,
        bd=0,
        highlightthickness=0,
        relief="ridge",
        background="#333333",
    ).pack()
    Label(
        pane,
        text=title,
        width=40,
        background="#333333",
        foreground="#fcffff",
        font=("Helvetica", 11),
    ).pack()
    Canvas(
        pane,
        width=400,
        height=20,
        bd=0,
        highlightthickness=0,
        relief="ridge",
        background="#333333",
    ).pack()

    main_text_label = Text(
        pane,
        width=45,
        height=6,
        bd=0,
        highlightthickness=0,
        relief="ridge",
        background="#333333",
        foreground="#b5b5b5",
        font=("Helvetica", 11),
        wrap=WORD,
    )
    main_text_label.tag_configure("center", justify="center")
    main_text_label.insert(INSERT, main_text)
    main_text_label.tag_add("center", "1.0", "end")
    main_text_label.config(state=DISABLED)
    main_text_label.pack()

    pane.pack()

    root.mainloop()


# Traceback (RuntimeError)
Traceback (most recent call last):
File "/home/sandip/personal/tribler/TriblerGUI/event_request_manager.py", line 99, in on_read_data
raise RuntimeError(json_dict["event"]["text"])
RuntimeError: [Failure instance: Traceback: <class 'apsw.FullError'>: FullError: database or disk is full
/usr/local/lib/python2.7/dist-packages/twisted/internet/base.py:1243:run
/usr/local/lib/python2.7/dist-packages/twisted/internet/base.py:1252:mainLoop
/usr/local/lib/python2.7/dist-packages/twisted/internet/base.py:878:runUntilCurrent
/usr/local/lib/python2.7/dist-packages/twisted/internet/task.py:239:__call__
--- <exception caught here> ---
/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py:150:maybeDeferred
/home/sandip/personal/tribler/Tribler/Core/CacheDB/SqliteCacheDBHandler.py:1285:_flush_to_database
/home/sandip/personal/tribler/Tribler/dispersy/util.py:46:helper
/home/sandip/personal/tribler/Tribler/dispersy/util.py:225:blockingCallFromThread
/home/sandip/personal/tribler/Tribler/Core/CacheDB/sqlitecachedb.py:308:executemany

# Fixed code
def error_and_exit(title, main_text):
    """
    Show a pop-up window and sys.exit() out of Python.

    :param title: the short error description
    :param main_text: the long error description
    """
    # NOTE: We don't want to load all of these imports normally.
    #       Otherwise we will have these unused GUI modules loaded in the main process.
    from Tkinter import Tk, Canvas, DISABLED, INSERT, Label, Text, WORD

    root = Tk()
    root.wm_title("Tribler: Critical Error!")
    root.wm_minsize(500, 300)
    root.wm_maxsize(500, 300)
    root.configure(background="#535252")

    # Place the window at the center
    root.update_idletasks()
    w = root.winfo_screenwidth()
    h = root.winfo_screenheight()
    size = tuple(int(_) for _ in root.geometry().split("+")[0].split("x"))
    x = w / 2 - 250
    y = h / 2 - 150
    root.geometry("%dx%d+%d+%d" % (size + (x, y)))

    Canvas(
        root,
        width=500,
        height=50,
        bd=0,
        highlightthickness=0,
        relief="ridge",
        background="#535252",
    ).pack()
    pane = Canvas(
        root,
        width=400,
        height=200,
        bd=0,
        highlightthickness=0,
        relief="ridge",
        background="#333333",
    )
    Canvas(
        pane,
        width=400,
        height=20,
        bd=0,
        highlightthickness=0,
        relief="ridge",
        background="#333333",
    ).pack()
    Label(
        pane,
        text=title,
        width=40,
        background="#333333",
        foreground="#fcffff",
        font=("Helvetica", 11),
    ).pack()
    Canvas(
        pane,
        width=400,
        height=20,
        bd=0,
        highlightthickness=0,
        relief="ridge",
        background="#333333",
    ).pack()

    main_text_label = Text(
        pane,
        width=45,
        height=6,
        bd=0,
        highlightthickness=0,
        relief="ridge",
        background="#333333",
        foreground="#b5b5b5",
        font=("Helvetica", 11),
        wrap=WORD,
    )
    main_text_label.tag_configure("center", justify="center")
    main_text_label.insert(INSERT, main_text)
    main_text_label.tag_add("center", "1.0", "end")
    main_text_label.config(state=DISABLED)
    main_text_label.pack()

    pane.pack()

    root.mainloop()

    # Exit the program
    sys.exit(1)