Hi guys,

So I'm busy writing an application that needs to update a list from the web after a certain amount of time.

main.py file

class Gui:
    def ......

    def ......

    def ......

    def on_update_click():
        update()

app=Gui()
Gtk.main()

So when the program loads up, user will click the update button to update the list.
I'd like the list to be updated every 6 hrs, so the update function should still run in the background

update.py file:

def update():
    #update list
    time.sleep(6hrs)

I suspect I'll have to use threading.
my thinking is:

Gtk.main() runs #thread 1
when the user clicks the update button, update() runs #thread 2
when update() has gone to sleep, go back to Gtk.main() #thread 1 or start new thread 3

Is my thinking correct or have i missed something

Recommended Answers

All 2 Replies

I think in GUIs generally you just set user timer event after 6 hours for update event and do nothing. No threads are needed.

So I found my solution:

from gi.repository import Gtk, GObject
from threading import Thread

GObject.threads.init() #allow threads to run serially
    class Gui:
        def ......
        def ......
        def ......
        def on_update_click():
            Thread(target=update).start() #start thread when button clicked

app=Gui()
Gtk.main()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.