|
Joined: Nov 2001
Posts: 1,704
Moderator / Da Masta
|
Moderator / Da Masta
Joined: Nov 2001
Posts: 1,704 |
I'm writing a Perl script (note: not CGI, it runs from the command line), and I want something to execute after 3 minutes. This means I need a timer of some sort. However, I don't want to use sleep because nothing else in the script will execute during those 3 minutes, which isn't good. Could anyone point me towards some kind of module or code or something to help get this done, please?
|
|
|
|
Joined: May 2000
Posts: 1,356
Addict
|
Addict
Joined: May 2000
Posts: 1,356 |
sleep is not *really* a timer... but alarm() is [code][/code]use in a command line script or in a cgi script... it does not matter, as long as the platform supports alarm()
|
|
|
|
Joined: Nov 2001
Posts: 1,704
Moderator / Da Masta
|
Moderator / Da Masta
Joined: Nov 2001
Posts: 1,704 |
Burak to the rescue once again! I'm having trouble getting that working, though... your_code() will execute straight after the script is executed, ignoring what I set $TIMEOUT as... Is there anything I'm missing? Thanks
|
|
|
|
Joined: May 2000
Posts: 1,356
Addict
|
Addict
Joined: May 2000
Posts: 1,356 |
if you write your code I can say something
|
|
|
|
Joined: Nov 2001
Posts: 1,704
Moderator / Da Masta
|
Moderator / Da Masta
Joined: Nov 2001
Posts: 1,704 |
I'm just pasting that into a fresh Perl script, and making a your_code() sub...
|
|
|
|
Joined: Nov 2001
Posts: 1,704
Moderator / Da Masta
|
Moderator / Da Masta
Joined: Nov 2001
Posts: 1,704 |
Ah... Just checked on ASPN and one reply said that alarm() only works on *NIX systems, not on Win32 systems. Is there a Win32 alternative to alarm(), either via a Perl module or another built-in function?
|
|
|
|
Joined: May 2000
Posts: 1,356
Addict
|
Addict
Joined: May 2000
Posts: 1,356 |
It can be win9x... alarm() works on 2000... Also some of the %SIG works on that platform...
|
|
|
|
Joined: May 2000
Posts: 1,356
Addict
|
Addict
Joined: May 2000
Posts: 1,356 |
quote:
Ah... Just checked on ASPN and one reply said that alarm() only works on *NIX systems, not on Win32 systems
I assume that you've checked old messages. What is the date of it? Also what perl version does he talks about and which version of windows does he/she uses? Also, which version of windows/perl do you use?
|
|
|
|
Joined: Nov 2001
Posts: 1,704
Moderator / Da Masta
|
Moderator / Da Masta
Joined: Nov 2001
Posts: 1,704 |
Me: WinXP Pro/ActivePerl 5.8.0 Them (the reply): Unspecified Win32 platforms/ActivePerl 5.6 Plus these posts were from 2001, so in retrospect there's a good chance of them being out of date. But that wouldn't explain why your code isn't working on my server...
|
|
|
|
Joined: May 2000
Posts: 1,356
Addict
|
Addict
Joined: May 2000
Posts: 1,356 |
Uhm... I have 5.8 build 804 also... try this one (you must get a timeout error): #!/usr/bin/perl -w use strict; my $TIMEOUT = 3; # seconds eval { local $SIG{ALRM} = sub { die "alarmn" }; alarm $TIMEOUT; your_code(); alarm 0; };
if ($@) { if($@ eq "alarmn") { error("OPERATION TIMED OUT!"); } else { error("your_code() generated errors: $@"); } }
sub your_code { for (1..1000000) { print "$_n"; } }
sub error { die "ERROR! ERROR! ERROR! @_"; }
|
|
|
|
Joined: Nov 2001
Posts: 1,704
Moderator / Da Masta
|
Moderator / Da Masta
Joined: Nov 2001
Posts: 1,704 |
Yes It'll print up to 13095 before giving the ERROR! ERROR! ERROR! thing with "operation timed out". Then it dies.
|
|
|
|
Joined: May 2000
Posts: 1,356
Addict
|
Addict
Joined: May 2000
Posts: 1,356 |
Then, alarm() and $SIG{ALRM} signal is working on your platform I think that the problem lies inside your code...
|
|
|
|
Joined: Nov 2001
Posts: 1,704
Moderator / Da Masta
|
Moderator / Da Masta
Joined: Nov 2001
Posts: 1,704 |
Excellent... I had an idea that it'd be my fault, it usually is Here's the deal: I've written an AIM bot, and I want to add a !poll feature to it. People can create polls and registered users of the bot have 3 minutes to vote on that poll before the poll is closed, the votes counted and the results IMed to the poll starter. Using Net::AIM, how would I fit this into my script? In my eyes it seems impossible... Thanks again Burak
|
|
|
|
Joined: May 2000
Posts: 1,356
Addict
|
Addict
Joined: May 2000
Posts: 1,356 |
well well... sorry but I dont use aim (basically I hate it) and I cant examine/test the module
|
|
|
Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.
Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
|
|
Posts: 1,157
Joined: July 2001
|
|
Forums63
Topics37,573
Posts293,925
Members13,849
|
Most Online5,166 Sep 15th, 2019
|
|
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
|
|
|
|