Advertisement

04.04.2008 at 01:20PM PDT, ID: 23297306
[x]
Attachment Details

Perl Fork/Threads issue in windows with tk splashscreen

Asked by BlakeEM in Perl Programming Language, Open Source Programming

Tags: Perl, ActivePerl, 5.10.0, Perk/TK, NA, NA

I have tried everything I could think of to get this to work with no luck. I have tried threads and fork with the same results.

What this does (or should do) is pop-up a TK Splashscreen with an animated gif while it's in the background downloading a file to test transfer speed. Once it's done I want to destroy the splashscreen and display the msg box.

The problem I am having is that I can't get both the splash screen and the file download/calculation to happen at the same time. When I try to fork it gives me errors like "Free to wrong pool 1823f98 not 224d48". From what I read you can only run TK interface stuff from the primary thread.

I tried to run the animation as the parent process and forking the speedTest but then I was having problems with not being able to kill the parent process (running the animation) from within the speedTest. I tried making all the interface variables in shared memory but that didn't seem to work or I wasn't doing it correctly.

Seeing as I don't know how long the speedTest will take I don't want to use a timeout for the splashscreen.

The code I have posted currently uses the threads. I assumed that the creation of a detached thread would cause it to run as a separate process however as it is now it never gets to the &doStuff part until the speedTest is done running.

It would be much appreciated if someone could point me in the right direction because I'm going in circles trying to figure it out.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
use LWP::Simple;
use Time::HiRes qw( gettimeofday tv_interval );
use Win32;
use strict;
use Tk;
use Tk::Splashscreen;
use Tk::Animation;
use threads;
 
 
my $file = "http://www.bio.sdsu.edu/Pub/lewison/conservation/uploads/Main/hammernoggin.jpg";
my $filesize = 1112264;
 
my @kbps;
my @downTime;
 
 
 
 
threads->create(\&speedTest())->detach;
 
&doStuff;
 
 
 
 
sub speedTest
{
 
 
   for(my $i=0;$i < 3; $i++)
   {
 
      my $t0 = [gettimeofday];
 
      my $content = get($file);
 
      die "Couldn't get it!" unless defined $content;
 
      $downTime[$i] = sprintf("%.2f", tv_interval ($t0));
 
      #math to figure download speed, added a 3.5% overhead.
      $kbps[$i] = (($filesize/$downTime[$i])/1024)*1.035;
 
   }
 
 
 
   @kbps = sort {$b <=> $a} (@kbps);
   @downTime = sort {$a <=> $b} (@downTime);
 
   my $avg = sprintf("%.2f", ($kbps[0]+$kbps[1]+$kbps[2])/3);
 
   #$sp->Destroy;
 
 
   Win32::MsgBox("Your Speed Test has been competed\r\n[".$downTime[0]." sec. ".sprintf("%.2f",($filesize/1024))." kb file]\r\n\r\n".
 
   "Avrage: ".$avg." kbps\r\n".
   "Peak:     ".sprintf("%.2f", $kbps[0])." kbps\r\n\r\n\r\n Razcon © 2008",
   MB_ICONINFORMATION,'Speed Test');
 
}
 
 
 
 
 
sub doStuff
{
 
   my $mw = MainWindow->new;
 
   $mw->withdraw();
 
   my $sp = $mw->Splashscreen;
 
   my $progress = $sp->Animation(-file   => "progress.gif", -format =>  "gif");
   my $icon = $sp->Label(-image => $progress)->pack();
   $progress->start_animation(150);
 
   $sp->Splash();
   $mw->MainLoop;
 
}
 
Keywords: Perl Fork/Threads issue in windows …
 
Loading Advertisement...
 
[+][-]04.04.2008 at 01:43PM PDT, ID: 21285508

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Perl Programming Language, Open Source Programming
Tags: Perl, ActivePerl, 5.10.0, Perk/TK, NA, NA
Sign Up Now!
Solution Provided By: Adam314
Participating Experts: 1
Solution Grade: A
 
 
[+][-]04.04.2008 at 02:29PM PDT, ID: 21285777

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628