[prev in list] [next in list] [prev in thread] [next in thread]
List: gtk-app-devel
Subject: Re: GTK threads and socket operations
From: Mathieu Comandon <strider () strycore ! com>
Date: 2014-11-26 11:23:05
Message-ID: 5475B819.1080207 () strycore ! com
[Download RAW message or body]
Hi!
Speaking of threading in Gtk, I'm using it quite extensively in my
application and never was really sure I was doing the right thing.
Here are the part in my codebase where I handle background jobs and
downloads:
https://github.com/lutris/lutris/blob/master/lutris/util/jobs.py
https://github.com/lutris/lutris/blob/master/lutris/downloader.py
Most of which is based on:
https://github.com/strycore/pygobject-demos/blob/master/background_task.py
Any feedback from experienced (python) GObject developers would be
greatly appreciated!
Thanks,
Mathieu
On 26/11/2014 11:27, Sergei Naumov wrote:
> Is there any tutorial on them? I searched the Web and did not find any good
> tutorial on GTK threads.
>
> -- Sergei O. Naumov
>
> 26.11.2014, 12:41:16 пользователь Bernhard Schuster
> (schuster.bernhard@gmail.com) написал:
>
>
> You modify your label from a thread that is not the main/ui thread.
> Gtk+ is not threadsafe (few exceptions). Use g_idle_add/ g_timeout_add/
> and
> friends (those are threadsafe) to implicitly serialize your ui
> modifications
> into the gtk mainloop.
>
> Do not use GDK_THREADS_ENTER/LEAVE foo unless you are maintaining a legacy
> codebase and you know exactly what this means including its implications.
>
> Best
>
> Bernhard
>
> On Nov 26, 2014 9:02 AM, "Sergei Naumov" <vomus@rambler.ru> wrote:
>
> Hi!
>
> I am writing an application that periodically reads data from network
> sockets
> (from Modbus enabled devices actually) and displays them in GTK+
> application. I
> read some tutorials about GTK threads and created a separate thread that
> encompasses Modbus reads and updates to GTK labels:
>
> modbus_thread = g_thread_new
> ("update_from_modbus",update_from_modbus,NULL);
>
> The update_from_modbus() has a bunch of socket reads (inside
> xantrex_read_value())
> and gtk_label_set_text()
>
> sprintf(params_val_text,"%-5.1f (%4.1f Hz)\n%-4.1f\n%-4d",
> 0.001*xantrex_read_value(modbus_pointer,0x004C,RECONSTRUCT_YES),
> 0.01*xantrex_read_value(modbus_pointer,0x004E,RECONSTRUCT_YES),
> 0.001*xantrex_read_value(modbus_pointer,0x0054,RECONSTRUCT_YES),
> xantrex_read_value(modbus_pointer,0x0052,RECONSTRUCT_YES));
> gtk_label_set_text (GTK_LABEL(ac1_params_val),params_val_text);
> gtk_label_set_justify(GTK_LABEL(ac1_params_val),GTK_JUSTIFY_LEFT);
>
> However after several hours I see crashes when the program tries to
> reconnect to
> my device. I tried to enclose GTK operations into gtk_threads_enter() /
> gtk_threads_leave() but it has no effect. Can anyone, please explain
> what
> is
> wrong here or may be point to a good example of multithreaded GTK code
> which has
> network socket operations in it?
>
> Thanks in advance,
>
> -- Sergei
> _______________________________________________
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
> _______________________________________________
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic