Previous Thread
Next Thread
Print Thread
Rate Thread
#104838 07/19/2003 7:32 PM
Joined: Nov 2001
Posts: 1,704
CTM
Offline
Moderator / Da Masta
Moderator / Da Masta
Offline
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? smile

Sponsored Links
#104839 07/19/2003 7:59 PM
Joined: May 2000
Posts: 1,356
Addict
Addict
Joined: May 2000
Posts: 1,356
sleep is not *really* a timer... but alarm() is smile

[code][/code]use in a command line script or in a cgi script... it does not matter, as long as the platform supports alarm()

#104840 07/22/2003 6:25 AM
Joined: Nov 2001
Posts: 1,704
CTM
Offline
Moderator / Da Masta
Moderator / Da Masta
Offline
Joined: Nov 2001
Posts: 1,704
Burak to the rescue once again! laugh

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 smile

#104841 07/22/2003 7:37 AM
Joined: May 2000
Posts: 1,356
Addict
Addict
Joined: May 2000
Posts: 1,356
if you write your code I can say something smile

#104842 07/29/2003 4:37 PM
Joined: Nov 2001
Posts: 1,704
CTM
Offline
Moderator / Da Masta
Moderator / Da Masta
Offline
Joined: Nov 2001
Posts: 1,704
I'm just pasting that into a fresh Perl script, and making a your_code() sub... smirk

Sponsored Links
#104843 07/29/2003 4:45 PM
Joined: Nov 2001
Posts: 1,704
CTM
Offline
Moderator / Da Masta
Moderator / Da Masta
Offline
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. frown

Is there a Win32 alternative to alarm(), either via a Perl module or another built-in function?

#104844 07/30/2003 6:01 AM
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...

#104845 07/30/2003 12:19 PM
Joined: May 2000
Posts: 1,356
Addict
Addict
Joined: May 2000
Posts: 1,356
Quote
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?

#104846 07/31/2003 11:00 AM
Joined: Nov 2001
Posts: 1,704
CTM
Offline
Moderator / Da Masta
Moderator / Da Masta
Offline
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. smirk But that wouldn't explain why your code isn't working on my server...

#104847 07/31/2003 11:15 AM
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):

Code
#!/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! @_";
}

Sponsored Links
#104848 07/31/2003 3:35 PM
Joined: Nov 2001
Posts: 1,704
CTM
Offline
Moderator / Da Masta
Moderator / Da Masta
Offline
Joined: Nov 2001
Posts: 1,704
Yes smile It'll print up to 13095 before giving the ERROR! ERROR! ERROR! thing with "operation timed out". Then it dies.

#104849 07/31/2003 3:43 PM
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 wink

I think that the problem lies inside your code...

#104850 08/01/2003 7:06 PM
Joined: Nov 2001
Posts: 1,704
CTM
Offline
Moderator / Da Masta
Moderator / Da Masta
Offline
Joined: Nov 2001
Posts: 1,704
Excellent... I had an idea that it'd be my fault, it usually is wink

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 smile

#104851 08/06/2003 11:32 AM
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 frown


Link Copied to Clipboard
Donate Today!
Donate via PayPal

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.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
isaac
isaac
California
Posts: 1,157
Joined: July 2001
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20221218)