Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Long running Perl Tk processes

by thundergnat (Deacon)
on May 30, 2008 at 15:50 UTC ( [id://689262]=note: print w/replies, xml ) Need Help??


in reply to Long running Perl Tk processes

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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-19 22:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found