home > 比較編 > Perl, PHP, Python, Ruby > dates and time >

ForNext

Only Do What Only You Can Do

092. timeout

VBScript

JScript

Perl

eval {
  $SIG{ALRM}= sub {die "timeout!";};
  alarm 5;
  sleep 10;
};
alarm 0;










PHP

use set_time_limit to limit execution time of the entire script; use stream_set_timeout to limit time spent reading from a stream opened with fopen or fsockopen















Python

import signal, time

class Timeout(Exception): pass

def timeout_handler(signo, fm):
  raise Timeout()

signal.signal(signal.SIGALRM,
  timeout_handler)

try:
  signal.alarm(5)
  time.sleep(10)
except Timeout:
  pass
signal.alarm(0)

Ruby

require 'timeout'

begin
  Timeout.timeout(5) do
    sleep(10)
  end
rescue Timeout::Error
end








PowerShell

Scala

F#

C

C++

C++Builder

VC++

C#

Java

Objective-C

D

VB

VB.NET

Delphi

Ada

PL/SQL

T-SQL

関数型

inserted by FC2 system