Hello,
First I have to warn that I am very new to programming and to Perl, so I apology if I'm asking what might well be stupid questions.
My project:
For some reasons that I can't affect, my program is made of two Perl scripts, one that I'll call gui.pl in charge of the UI and the other one performing a long computation, I'll call it compute.pl.
The computation is a long process (from 20sec to X minutes) and I need to display its progress in the UI. In the middle of compute.pl, one specific variable can be used as a progress indicator: while compute.pl is running this value will increase (at a high refresh rate, "some" ms).
Problem:
So far, I have been successful using IPC::Shareable to store this value from compute.pl (for each row treated, the new value is pushed to my IPC shared memory) and read it at the same time in gui.pl (in a loop, every 250ms). Great...on a mac or linux. My application must also work on Windows machines, and it doesn't look like IPC::Shareable can be used there.
What is the best replacement for my usage?
Constraints:
* I execute compute.pl from gui.pl using Threads, to avoid freezing the UI while computing.
* From what I understood (but I can be totally wrong), I can't use pipes, as the output of compute.pl is already a file. At least I haven't been successful using pipes.
The command to execute compute.pl looks like: "perl compute.pl -arg1 arg2 arg3 arg4 sourcefile.txt > destinationfile.txt"
What I've tried so far was to use Win32::MMF::Shareable, but it crashes as soon as I attempt to read the value from gui.pl. Remember: compute.pl is "permanently" writing on it.
I must say I'm a bit lost. I usually never write posts like that, I always find the information even if some hours of research are needed but this time, I'm stuck. :(
Thanks a lot for the help/advises.
-Guillaume
EDIT:
I'm posting here the solution I have adopted, in case google brings here someone with a similar problem :)
I've decided to incorporate compute.pl better (and lose a little bit of this independence I was mentioning) by wrapping its entire content into a subroutine and giving it a package name. This way I could export from compute.pl the subroutine and the variable needed to evaluate the progress of the computation.
Here is how it looks like in compute.pl:
and here is what I inserted in gui.pl:package compute; use strict; use warnings; use MCE::Shared; use base 'Exporter'; our @EXPORT_OK = qw/process $progress/; our $progress = MCE::Shared->scalar( 0 ); my @ARGV = @_; # I know this is dirty but that helps reducing the a +mount of modifications in compute.pl that uses @ARGV a lot sub process { open INPUT, '<', "@ARGV[9]" or die $!; #here I open the input file open OUTPUT, '>', "@ARGV[10]" or die $!; #here I open the output file STDIN->fdopen( \*INPUT, 'r' ) or die $!; #here I set the input file STDOUT->fdopen( \*OUTPUT, 'w' ) or die $!; #here I set the output fil +e ...do all sort of computation... $progress->set("value_I_need"); } 1; }
use MCE::Shared; use compute qw/ process $progress /; sub my_loop_updating_the_progress { my $point_of_progress = $compute::progress->get(); ...do whatever I want with $point_of_progress... } sub launch computation { @arguments_needed = ( arg1, arg2, arg3, arg4 ... arg9, arg10); compute::process(@arguments_needed); }
Note that I execute sub progress and sub compute in thread 2 and thread 3, while my GUI is already using thread 1.
In reply to Shared memory and asynchronous access by vef445
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |