Re: advice needed for spinner



Hi,

Just to clarify a bit about forking and Gtk2 and Gtk3; when you use
fork() to launch processes, if you want to get information from your
child processes, you have to use a wait() call to wait for the
children to exit; this will cause the parent process to block.

With most GUI toolkits, Gtk2/Gtk3 included, you should never block the
process you run Gtk2/3 from, this will cause the UI to freeze.

Since you want to get information back from your child processes (so
you know when to stop and hide the spinner), you need to use sockets,
pipes, files, or some other type of interprocess communication (IPC)
to pass data back from your child processes to the parent process,
instead of having your parent process wait for your child processes to
exit.  For example, you could shut off the spinner in the parent fork
when your children fork(s) send the correct message to the parent fork
via some kind of IPC.  You could also use threads and IPC to do the
same thing.

There are more examples floating around of using threads versus using
forks with Gtk2, however, all of the examples that I have seen always
use some kind of IPC to pass messages back and forth between
parent/children processes in the case of forks, or amongst threads for
threaded processes. Threads can also use message queues to pass
messages back and forth between threads (but you can't pass blessed
Perl objects via thread queues). There's not really any examples of
IPC and threads/forks for Gtk3, but the procedure is the same between
the two versions.

I've included links to a few examples of both forks and threads with
Gtk2/3 and IPC, more can be had if you ask your favorite search engine
nicely (hint: try "perl gtk2 fork" or "perl gtk2 thread"), search in
the mailing list archives, or go search on Perlmonks, zentara has
written quite a few messages about threads on Perlmonks.

Thanks,

Brian

URLs about forking/threading and using IPC in Gtk2:

https://mail.gnome.org/archives/gtk-perl-list/2003-November/msg00033.html
https://metacpan.org/source/XAOC/Gtk2-1.2491/examples/thread_usage.pl
https://mail.gnome.org/archives/gtk-perl-list/2003-November/msg00028.html

On Sun, Jun 1, 2014 at 4:50 PM, tsuyoshi okita <825864 gmail com> wrote:
Dear Guru,

Thank you for your replies and time. I am no expert in this field.  I am
very sure you all have noticed by now*_*
I will study again with your codes provided.  Thank you, Marius and Zentara.
Brian, thank you for your effort.
Wax on, wax off, practice harder, Daniel-san!!
anyway, thank you again for your help.

Tsuyoshi


On 2014年06月02日 02:24, zentara wrote:

On Thu, 29 May 2014 11:27:27 +0900
tsuyoshi okita <825864 gmail com> wrote:

Dear gurus,

I've been trying let a spinner spins at the same time sending an email
by forking and failing.  Although a program forks, and one child process

After reading all the replies by Brian Manning concerning
the difficulty of controlling the widget thru forks, I would
like to remind you that threads do a good job with this,
if you do it correctly.
( My code below may not be correct, but it works. :-)
 See http://www.perlmonks.org?node_id=804402 for
a discussion.

I'm not delving into Gtk3 yet, but the attached Gtk2 code
should be modifiable to Gtk3.

0m,
zentara



_______________________________________________
gtk-perl-list mailing list
gtk-perl-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-perl-list



_______________________________________________
gtk-perl-list mailing list
gtk-perl-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-perl-list



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]