Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^6: Spinning cursor while waiting for search/copy process to be finished

by Anonymous Monk
on Mar 26, 2013 at 12:19 UTC ( #1025510=note: print w/ replies, xml ) Need Help??


in reply to Re^5: Spinning cursor while waiting for search/copy process to be finished
in thread Spinning cursor while waiting for search/copy process to be finished

Sorry, there is one more thing: suppose, the process is just in one statement, not a loop:

copy ("$source", "$destination");

It does take long because the source is a big file on a network resource. I tried it this way:

while (my $result = copy ("$source", "$destination")) { spin($j); }

But I don't quite like what is going on: it spins, then makes a long pause, then spings again... Is there any trick I could use to make them work as if in parallel?


Comment on Re^6: Spinning cursor while waiting for search/copy process to be finished
Select or Download Code
Re^7: Spinning cursor while waiting for search/copy process to be finished
by aitap (Deacon) on Mar 26, 2013 at 17:02 UTC

    You can fork a new process and make it run the spinner, or create a thread running a spinning function. Link to an example solution was posted in Re: Spinning cursor while waiting for search/copy process to be finished.

    Forking spinner can be easier to write, but it must be noted that you may have problems killing the spinner process on platforms not supporting fork syscall natively (win32, for example). Search safe signals win32 for more information. Update: child is not blocked in writing operation continiousely, so signals should not be a problem.

    my $j = 0; if ((my $pid = fork()) == 0) { # this runs in child process do {sleep 0.5; spin($j)} while 1; # normally we should put some kind of exit statement here, but the lo +op above is infinite } elsif ($pid > 0) { # parent/main process ...; # put your loop here kill 1, $pid; # stop the spinner process waitpid $pid, 0; # this should help against zombies } else { # fork returned undef die "fork: $!\n"; }

    Sorry if my advice was wrong.

      Great! I have already learned so much, thank you! It works just as I need, I only changed

      kill 1, $pid;

      to

      kill 9, $pid;

      because of

      Terminating on signal SIGHUP(1)

      message.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1025510]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (11)
As of 2014-07-29 09:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (212 votes), past polls