Perl Tk: long running callback loses GUI interactivity

Perl Tk: long running callback loses GUI interactivity

am 20.11.2007 15:42:25 von Andy

Hi,

I wonder if anyone can help me with a small perl Tk problem I have. I
am writing an automated test script for a digital radio system, when
the user has selected all the options for the test and hits GO in the
GUI the callback executes a long running script, when this happens the
Tk GUI is completley inactive until the call back is finished (which
can take hours). Ideally i'd still like the GUI to have some
interactivity, suck as a CANCEL button to stop the tests (currently I
have to do a Ctrl-C in the dos window to stop the test). Is there a
way to do this? I wasnt sure what search terms to look for when
investigating a solution.

Many thanks in advance,

Andy

Re: Perl Tk: long running callback loses GUI interactivity

am 20.11.2007 16:27:57 von sheinrich

On Nov 20, 3:42 pm, andy wrote:

> GUI the callback executes a long running script, when this happens the
> Tk GUI is completley inactive until the call back is finished (which
> can take hours). Ideally i'd still like the GUI to have some

This is no issue with perl or tk. The implications are very much the
same with any language across all OSes.
You are apparently running a single process.

I don't know, but tk might have its build-in solutions for a rather
central point in gui functionality.
Else look up "IPC", "parallel" and "fork" in your favourite perl docs
and on CPAN.

You have multiple options to deal with user interaction.
- Your long lasting program might occasionally check for user input to
process.
- You can start an own process with fork() for the long routine and
can steer the child process by means of IPC (inter process
communication). Usually pipes or signals.

fork() is basically easy to use, if your system is supporting it. Try
one of the many examples and find out.

steffen

Re: Perl Tk: long running callback loses GUI interactivity

am 20.11.2007 16:46:02 von smallpond

On Nov 20, 10:27 am, sheinr...@my-deja.com wrote:
> On Nov 20, 3:42 pm, andy wrote:
>
> > GUI the callback executes a long running script, when this happens the
> > Tk GUI is completley inactive until the call back is finished (which
> > can take hours). Ideally i'd still like the GUI to have some
>
> This is no issue with perl or tk. The implications are very much the
> same with any language across all OSes.
> You are apparently running a single process.
>
> I don't know, but tk might have its build-in solutions for a rather
> central point in gui functionality.
> Else look up "IPC", "parallel" and "fork" in your favourite perl docs
> and on CPAN.
>
> You have multiple options to deal with user interaction.
> - Your long lasting program might occasionally check for user input to
> process.
> - You can start an own process with fork() for the long routine and
> can steer the child process by means of IPC (inter process
> communication). Usually pipes or signals.
>
> fork() is basically easy to use, if your system is supporting it. Try
> one of the many examples and find out.
>
> steffen


fork() is a good solution. Have the parent return to MainLoop (which
is
what needs to be running for the GUI activity) while the child
executes
your long-running process. system() can be used to start a separate
process that will not interfere with MainLoop. Just be sure to call
it
with 'myprocess &' so it doesn't wait for completion.
--S

Re: Perl Tk: long running callback loses GUI interactivity

am 20.11.2007 17:26:19 von Petr Vileta

andy wrote:
> Hi,
>
> I wonder if anyone can help me with a small perl Tk problem I have. I
> am writing an automated test script for a digital radio system, when
> the user has selected all the options for the test and hits GO in the
> GUI the callback executes a long running script, when this happens the
> Tk GUI is completley inactive until the call back is finished (which
> can take hours). Ideally i'd still like the GUI to have some
> interactivity, suck as a CANCEL button to stop the tests (currently I
> have to do a Ctrl-C in the dos window to stop the test). Is there a
> way to do this? I wasnt sure what search terms to look for when
> investigating a solution.
>
I see you are talking about DOS window ;-) In this case go to CPAN and
search for module ProcFarm. This is something similar to unix fork() but
work very good on Win platform.
--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)

Re: Perl Tk: long running callback loses GUI interactivity

am 20.11.2007 20:12:20 von smallpond

On Nov 20, 10:46 am, smallpond wrote:
> On Nov 20, 10:27 am, sheinr...@my-deja.com wrote:
>
>
>
> > On Nov 20, 3:42 pm, andy wrote:
>
> > > GUI the callback executes a long running script, when this happens the
> > > Tk GUI is completley inactive until the call back is finished (which
> > > can take hours). Ideally i'd still like the GUI to have some
>
> > This is no issue with perl or tk. The implications are very much the
> > same with any language across all OSes.
> > You are apparently running a single process.
>
> > I don't know, but tk might have its build-in solutions for a rather
> > central point in gui functionality.
> > Else look up "IPC", "parallel" and "fork" in your favourite perl docs
> > and on CPAN.
>
> > You have multiple options to deal with user interaction.
> > - Your long lasting program might occasionally check for user input to
> > process.
> > - You can start an own process with fork() for the long routine and
> > can steer the child process by means of IPC (inter process
> > communication). Usually pipes or signals.
>
> > fork() is basically easy to use, if your system is supporting it. Try
> > one of the many examples and find out.
>
> > steffen
>
> fork() is a good solution. Have the parent return to MainLoop (which
> is
> what needs to be running for the GUI activity) while the child
> executes
> your long-running process. system() can be used to start a separate
> process that will not interfere with MainLoop. Just be sure to call
> it
> with 'myprocess &' so it doesn't wait for completion.
> --S

My mistake. Tk cannot call fork in a callback. If using fork
in a Tk program, call it before calling MainLoop.
system is OK, tho.
--S

Re: Perl Tk: long running callback loses GUI interactivity

am 21.11.2007 13:15:20 von zentara

On Tue, 20 Nov 2007 11:12:20 -0800 (PST), smallpond
wrote:
>
>My mistake. Tk cannot call fork in a callback. If using fork
>in a Tk program, call it before calling MainLoop.
>system is OK, tho.
>--S

Whoa, that is bad info. Tk can call fork anywhere it wants. You may be
confusing fork with the Tk thread safety problem.

zentara


--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html

Re: Perl Tk: long running callback loses GUI interactivity

am 21.11.2007 13:15:21 von zentara

On Tue, 20 Nov 2007 06:42:25 -0800 (PST), andy
wrote:

>Hi,
>
>I wonder if anyone can help me with a small perl Tk problem I have. I
>am writing an automated test script for a digital radio system, when
>the user has selected all the options for the test and hits GO in the
>GUI the callback executes a long running script, when this happens the
>Tk GUI is completley inactive until the call back is finished (which
>can take hours). Ideally i'd still like the GUI to have some
>interactivity, suck as a CANCEL button to stop the tests (currently I
>have to do a Ctrl-C in the dos window to stop the test). Is there a
>way to do this? I wasnt sure what search terms to look for when
>investigating a solution.
>
>Many thanks in advance,
>
>Andy

You have only one choice, if you want to keep the gui going AND
you want to cancel at any time..... run the command thru a piped-open
or IPC::Open3 ( or IPC::Run, Win32::Pipe, etc).

The reason for this, is you will need to get the pid of the process, so
you can kill it( your cancel).

See:
http://perlmonks.org?node_id=506909
and
http://perlmonks.org?node_id=463896


zentara


--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html

Re: Perl Tk: long running callback loses GUI interactivity

am 21.11.2007 15:02:11 von Petr Vileta

zentara wrote:
> On Tue, 20 Nov 2007 06:42:25 -0800 (PST), andy
> wrote:
>
> You have only one choice, if you want to keep the gui going AND
> you want to cancel at any time..... run the command thru a piped-open
> or IPC::Open3 ( or IPC::Run, Win32::Pipe, etc).
>
I found a very good solution for Win platform on CPAN. This module is called
ProcFarm and work excelently. Maybe we can ask an author to make this module
platform independent ;-)
--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)

Re: Perl Tk: long running callback loses GUI interactivity

am 21.11.2007 18:32:35 von Ben Morrow

Quoth zentara :
> On Tue, 20 Nov 2007 11:12:20 -0800 (PST), smallpond
> wrote:
> >
> >My mistake. Tk cannot call fork in a callback. If using fork
> >in a Tk program, call it before calling MainLoop.
> >system is OK, tho.
>
> Whoa, that is bad info. Tk can call fork anywhere it wants. You may be
> confusing fork with the Tk thread safety problem.

The OP is on Win32, so they are equivalent (fork is implemented with
threads on Win32).

Ben