0

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

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Zeref
0

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

0

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()
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.