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

Long running Perl Tk processes

by greenFox (Vicar)
on May 30, 2008 at 14:33 UTC ( #689224=perlquestion: print w/ replies, xml ) Need Help??
greenFox has asked for the wisdom of the Perl Monks concerning the following question:

Does any-one have any experience with long running Perl Tk applications? By long running I mean longer than a week. I've written a proof of concept application for the mob I work for and I'm wondering if I'm likely to see memory leaks or any other nastiness. My code doesn't do anything magical or complex but I don't have any experience with Perl Tk running for more than a few hours... I kicked one off a couple of days ago and it looks OK so far but I thought I would check out the collective wisdom whilst I am waiting...

Thanks.
Murray

--
Murray. Do not seek to follow in the footsteps of the wise. Seek what they sought. -Basho

Comment on Long running Perl Tk processes
Re: Long running Perl Tk processes
by zentara (Archbishop) on May 30, 2008 at 15:43 UTC
    All you can do is test it. Tk is pretty good If it dosn't change images or widgets frequently. It should remain memory stable. Here is a little test script I use to watch memory. Things to watch out for are destroying widgets, or changes images. See linux memory leak monitor

    I'm not really a human, but I play one on earth CandyGram for Mongo
Re: Long running Perl Tk processes
by thundergnat (Deacon) on May 30, 2008 at 15:50 UTC

    I have a Perl::Tk based script that does state mandated process monitoring and data collection for some industrial processes in the manufacturing plant where I work. (Serial interface to some National Instrument FieldPoint IO.) We need to do continuous monitoring with some fairly substantial fines if we exceed a threshold of downtime so I was concerned about this myself.

    I ended up setting up the script to re exec itself once a day to avoid any side effects of memory leaks. You lose a second or two while it restarts but memory leaks can't get big enough to cause problems.

    Here are the relevant bits. (Note: this is chopped out of a much larger script so some variables are artificially localized and/or not used in this fragment.)

    use warnings; use strict; use Tk; use Date::Calc qw( Today_and_Now Add_Delta_DHMS ); use constant OS_Win => $^O =~ /Win/; my $last_time; my $time_zone = -5; # GMT-5 or, EST. Set TZ appropriately my $mw = MainWindow->new; my $repeat = $mw->repeat( 250, \&update ); MainLoop; sub update{ my ( $year, $month, $day, $hour, $minute, $second ) = Add_Delta_DHMS( Today_and_Now( [localtime] ), 0, $time_zone, 0, +0 ); # Restart the program every day at midnight. Sidestep a bunch of # memory leak problems. if ( ( "$hour$minute$second" eq '000' ) and ( $last_time eq '23595 +9' ) ) { OS_Win ? exec "wperl $0" : exec "perl $0 &"; } $last_time = "$hour$minute$second"; warn "$last_time\n"; # for testing purposes }

    I'm not saying this is the only or best solution, but it works for me. The script this was taken from has been running "continuously" for the past several years.

Re: Long running Perl Tk processes
by graff (Chancellor) on May 31, 2008 at 05:52 UTC
    If the widget inventory in the app remains stable/fixed (i.e. you are not creating lots of new widgets as part of the user interaction), and you're always just (re)using the same variable storage for data content being displayed in the widgets (e.g. "-textvariable" attributes for Label and Entry widgets, the same array for Listbox widgets, etc), it should run indefinitely with an unchanging memory footprint.

    But as zentara says, you just have to test it out (and as most monks know, zentara is, hands-down, the top authority here on all things Tk).

      I'm not creating or destroying widgets but I do pack() and packForget() a little bit. Its run for a week without growing so I think it will be OK. Will dig further if I need to...

      Thanks.
      Murray

      --
      Murray. Do not seek to follow in the footsteps of the wise. Seek what they sought. -Basho

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2014-12-21 06:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (104 votes), past polls