Re: Best way to busy-wait in Python 3 / Gtk+ 3?
On 10/10/2012 06:17 AM, Filip Lamparski wrote: Thanks, your method works. However, it still takes the program quite a bit to load up, and my problem is that I want display the window as soon as possible. If that helps, here is how the program loads up: Script starts The window is constructed Window events are connected to their handlers window.show_all() When the window is ready, TED Talks are loaded and processed. Then, widgets for the talks are created. In the widget's constructor, I call GdkPixbuf.Pixbuf.new_from_stream_async. Problem: The window does not show up when loading the images (something that I hoped _async would make possible). Hmm the point of async is to load things in the background. So somewhere something is missing. You'll have to post some small code example I think. Preferably a complete snippet that replicates the problem (show a single window, do a single image load or something). ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Best way to busy-wait in Python 3 / Gtk+ 3?
Thanks, your method works. However, it still takes the program quite a bit to load up, and my problem is that I want display the window as soon as possible. If that helps, here is how the program loads up: Script starts The window is constructed Window events are connected to their handlers window.show_all() When the window is ready, TED Talks are loaded and processed. Then, widgets for the talks are created. In the widget's constructor, I call GdkPixbuf.Pixbuf.new_from_stream_async. Problem: The window does not show up when loading the images (something that I hoped _async would make possible). On 8 October 2012 08:32, Simon Feltman s.felt...@gmail.com wrote: On Sun, Oct 7, 2012 at 9:10 PM, Michael Torrie torr...@gmail.com wrote: Maybe the best way is to avoid processes or threads altogether. Since downloading this thumbnail is io-bound, not cpu-bound, once you send off your request, just use io watches to trigger the main loop when something has come in. Agreed, better yet, the code could become much simpler using an async pixbuf: def on_image_ready(stream, res, user_data): pixbuf = GdkPixbuf.Pixbuf.new_from_stream_finish(res) ... file = Gio.File.new_for_uri(...) GdkPixbuf.Pixbuf.new_from_stream_async(file.read(None), None, on_image_ready, None) All within a main loop of course. -Simon ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list -- _ Filip Lamparski - FB https://www.facebook.com/filip.lamparski - G+https://plus.google.com/105688569486178456264/posts ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Best way to busy-wait in Python 3 / Gtk+ 3?
On Sun, Oct 7, 2012 at 9:10 PM, Michael Torrie torr...@gmail.com wrote: Maybe the best way is to avoid processes or threads altogether. Since downloading this thumbnail is io-bound, not cpu-bound, once you send off your request, just use io watches to trigger the main loop when something has come in. Agreed, better yet, the code could become much simpler using an async pixbuf: def on_image_ready(stream, res, user_data): pixbuf = GdkPixbuf.Pixbuf.new_from_stream_finish(res) ... file = Gio.File.new_for_uri(...) GdkPixbuf.Pixbuf.new_from_stream_async(file.read(None), None, on_image_ready, None) All within a main loop of course. -Simon ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Best way to busy-wait in Python 3 / Gtk+ 3?
It looks like I could put it into the constructor for the TEDTalkWidget, right? Because that would be awesome. On 8 October 2012 08:32, Simon Feltman s.felt...@gmail.com wrote: Agreed, better yet, the code could become much simpler using an async pixbuf: def on_image_ready(stream, res, user_data): pixbuf = GdkPixbuf.Pixbuf.new_from_stream_finish(res) ... file = Gio.File.new_for_uri(...) GdkPixbuf.Pixbuf.new_from_stream_async(file.read(None), None, on_image_ready, None) All within a main loop of course. -Simon ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list -- _ Filip Lamparski - FB https://www.facebook.com/filip.lamparski - G+https://plus.google.com/105688569486178456264/posts ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Best way to busy-wait in Python 3 / Gtk+ 3?
On 6 October 2012 15:48, Filip Lamparski matka.pooha...@gmail.com wrote: However, the thumbnail loading process takes a long time, so I want to put it into another process, with the GUI displaying a spinner or a progress bar until the loading finishes. Sorry, I don't use Python much, but in C you'd start a thread to do the load and then have that call g_idle_add() when it finished. Meanwhile the main thread stays just handling inputs and repaints, but you display some sort of busy indicator until the idle callback fires. Something like: on_load_button_click: busy = True update_view start worker thread worker thread: load thumbnail g_idle_add (thumbnail_done, thumbnail) thumbnail_done (thumbnail) busy = False set thumbnail update_view John ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Best way to busy-wait in Python 3 / Gtk+ 3?
I specifically want to avoid using GLib's threading machinery in order to use multiprocessing, since later I want to add multithreading to the thumbnail loading process itself in order to utilise multiple cores more efficiently. That is because at first run, I have to download 128 images, and the server tends to take its sweet time. On 7 October 2012 10:23, jcup...@gmail.com wrote: Sorry, I don't use Python much, but in C you'd start a thread to do the load and then have that call g_idle_add() when it finished. Meanwhile the main thread stays just handling inputs and repaints, but you display some sort of busy indicator until the idle callback fires. John -- _ Filip Lamparski - FB https://www.facebook.com/filip.lamparski - G+https://plus.google.com/105688569486178456264/posts ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Best way to busy-wait in Python 3 / Gtk+ 3?
Sorry I missed the process bit. To have the load in another process, use a pipe to send worker results back to the main process, and add the pipe to your gtk main loop as an event source. You obviously can't use any gtk/glib stuff in your worker, you'd need to just make a .jpg, then do all the widget stuff in the main process, On 7 October 2012 12:34, Filip Lamparski matka.pooha...@gmail.com wrote: I specifically want to avoid using GLib's threading machinery in order to use multiprocessing, since later I want to add multithreading to the thumbnail loading process itself in order to utilise multiple cores more efficiently. That is because at first run, I have to download 128 images, and the server tends to take its sweet time. On 7 October 2012 10:23, jcup...@gmail.com wrote: Sorry, I don't use Python much, but in C you'd start a thread to do the load and then have that call g_idle_add() when it finished. Meanwhile the main thread stays just handling inputs and repaints, but you display some sort of busy indicator until the idle callback fires. John -- _ Filip Lamparski - FB - G+ ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Best way to busy-wait in Python 3 / Gtk+ 3?
On 7 October 2012 12:58, jcup...@gmail.com wrote: To have the load in another process, use a pipe to send worker results back to the main process, and add the pipe to your gtk main loop as an event source. Is there any way I could do that? I looked at GLib's main loop and Gtk's main loop, but can't seem to find it. You obviously can't use any gtk/glib stuff in your worker, you'd need to just make a .jpg, then do all the widget stuff in the main process, Figured as much. -- _ Filip Lamparski - FB https://www.facebook.com/filip.lamparski - G+https://plus.google.com/105688569486178456264/posts ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Best way to busy-wait in Python 3 / Gtk+ 3?
On Sun, Oct 7, 2012 at 12:29 PM, Filip Lamparski matka.pooha...@gmail.com wrote: On 7 October 2012 12:58, jcup...@gmail.com wrote: To have the load in another process, use a pipe to send worker results back to the main process, and add the pipe to your gtk main loop as an event source. Is there any way I could do that? I looked at GLib's main loop and Gtk's main loop, but can't seem to find it. Is the idea to have a first pass downloading image files in a separate process and then use a thread to load them into memory? I don't know much about GStreamer but it seems like it might be helpful technology in this realm. For completeness, you can use pythons multiprocessing module along with GLib's io watch: parent, child = multiprocessing.Pipe() GLib.io_add_watch(parent, GLib.IOCondition.IN, event_callback) process = multiprocessing.Process(target=worker_func, args=(child,)) process.start() -Simon ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Best way to busy-wait in Python 3 / Gtk+ 3?
On 10/07/2012 08:41 PM, Simon Feltman wrote: On Sun, Oct 7, 2012 at 12:29 PM, Filip Lamparski matka.pooha...@gmail.com wrote: On 7 October 2012 12:58, jcup...@gmail.com wrote: To have the load in another process, use a pipe to send worker results back to the main process, and add the pipe to your gtk main loop as an event source. Is there any way I could do that? I looked at GLib's main loop and Gtk's main loop, but can't seem to find it. Is the idea to have a first pass downloading image files in a separate process and then use a thread to load them into memory? I don't know much about GStreamer but it seems like it might be helpful technology in this realm. For completeness, you can use pythons multiprocessing module along with GLib's io watch: parent, child = multiprocessing.Pipe() GLib.io_add_watch(parent, GLib.IOCondition.IN, event_callback) process = multiprocessing.Process(target=worker_func, args=(child,)) process.start() Maybe the best way is to avoid processes or threads altogether. Since downloading this thumbnail is io-bound, not cpu-bound, once you send off your request, just use io watches to trigger the main loop when something has come in. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list