Threading in Gtk python

后端 未结 3 1378
甜味超标
甜味超标 2020-12-03 13:21

So I\'m busy writing an application that needs to check for updates from a website after a certain amount ouf time, I\'m using python with Gtk +3

main.py file

<
3条回答
  •  广开言路
    2020-12-03 13:42

    Threading is the first way to solve the problem. You can create thread and run long-running blocking function inside that thread (and your GUI won't hang up).

    Another way is to use asynchronous networking e.g. using python-gio (GObject-IO) or another library that has a possibility to work with GLib's main loop (like they do with Twisted). This approach is a bit different and uses non-blocking socket operations. Your main loop will make a callback when data from socket (site you're polling) will be available to read. Unfortunately GIO has no high-level HTTP API, so you can use GSocketClient and manually create HTTP requests structure.

提交回复
热议问题