Groups | Search | Server Info | Login | Register
Groups > de.comp.lang.perl > #550
| From | Thomas Dorner <dclp250130.dorner@spamgourmet.com> |
|---|---|
| Newsgroups | de.comp.lang.perl |
| Subject | Re: alarm() wird nicht ausgefiehrt |
| Date | 2025-01-30 18:02 +0100 |
| Message-ID | <6emsf8w7ym.fsf@th-dorner.de> (permalink) |
| References | <vnfptq$22l$1@rusnews.informatik.uni-stuttgart.de> <6er04kwgko.fsf@th-dorner.de> <vng7mi$5ao$1@rusnews.informatik.uni-stuttgart.de> |
Ulli Horlacher <framstag@rus.uni-stuttgart.de> writes:
> Thomas Dorner <dclp250130.dorner@spamgourmet.com> wrote:
>
>>> Leider haengt der Prozess:
>>>
>>> fex@fex01:~n: strace -p 26157
>>> strace: Process 26157 attached
>>> write(1, "HTTP/1.0 200 INTERNAL ERROR\r\n", 29
>>>
>>>
>>> Der Code an der Stelle ist:
>>>
>>> local $SIG{ALRM} = sub { exit 99 };
>>> alarm(3);
>>> print "HTTP/1.0 200 INTERNAL ERROR\r\n";
>>>
>>>
>>> Eigentlich sollte doch nach spaetestens 3 Sekunden sich das Programm
>>> beenden. Warum nicht?
>>
>> System-Call? Die benötigen zusätzlichen Code, siehe perldoc alarm ganz
>> am Ende.
>
> Ist write ein system call?
Letztlich ja.
> In perldoc alarm steht:
>
> local $SIG{ALRM} = sub { die "alarm\n" };
> alarm $timeout;
> my $nread = sysread $socket, $buffer, $size;
>
> Also sehr aehnlicher Code wie bei mir.
> Da wird der alarm ausgefuehrt, bei mir bleibt das write aber haengen und
> wird nicht vom alarm unterbrochen.
>
>
> Dort wird nur das Setzen von $! diskutiert, das ist mir aber egal.
> Ich will nur nicht, dass das Programm im write haengen bleibt.
perlipc empfiehlt den eval eigentlich immer:
#v+
Signal handling is also used for timeouts in Unix. While safely
protected within an "eval{}" block, you set a signal handler to trap
alarm signals and then schedule to have one delivered to you in some
number of seconds. Then try your blocking operation, clearing the alarm
when it's done but not before you've exited your "eval{}" block. If it
goes off, you'll use die() to jump out of the block.
Here's an example:
my $ALARM_EXCEPTION = "alarm clock restart";
eval {
local $SIG{ALRM} = sub { die $ALARM_EXCEPTION };
alarm 10;
flock($fh, 2) # blocking write lock
|| die "cannot flock: $!";
alarm 0;
};
if ($@ && $@ !~ quotemeta($ALARM_EXCEPTION)) { die }
#v-
Später wird auch erklärt, warum:
#v+
Perl 5.8.0 and later avoid these problems by "deferring" signals. That
is, when the signal is delivered to the process by the system (to the C
code that implements Perl) a flag is set, and the handler returns
immediately. Then at strategic "safe" points in the Perl interpreter
(e.g. when it is about to execute a new opcode) the flags are checked
and the Perl level handler from %SIG is executed. The "deferred" scheme
allows much more flexibility in the coding of signal handlers as we know
the Perl interpreter is in a safe state, and that we are not in a system
library function when the handler is called. [...]
#v-
Ohne jetzt direkt in den C Code von Perl zu schauen, gehe ich mal davon
aus, daß das genau Dein Problem ist.
Viele Grüße, Thomas
--
Adresse gilt nur kurzzeitig!
Back to de.comp.lang.perl | Previous | Next — Previous in thread | Next in thread | Find similar
alarm() wird nicht ausgefiehrt Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2025-01-30 12:05 +0000
Re: alarm() wird nicht ausgefiehrt Thomas Dorner <dclp250130.dorner@spamgourmet.com> - 2025-01-30 14:56 +0100
Re: alarm() wird nicht ausgefiehrt Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2025-01-30 16:00 +0000
Re: alarm() wird nicht ausgefiehrt Thomas Dorner <dclp250130.dorner@spamgourmet.com> - 2025-01-30 18:02 +0100
Re: alarm() wird nicht ausgefiehrt "Peter J. Holzer" <hjp-usenet4@hjp.at> - 2025-01-30 18:44 +0100
Re: alarm() wird nicht ausgefiehrt Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2025-01-30 21:46 +0000
Re: alarm() wird nicht ausgefiehrt Thomas Dorner <dclp250131.dorner@spamgourmet.com> - 2025-01-31 10:20 +0100
Re: alarm() wird nicht ausgefiehrt Ulli Horlacher <framstag@rus.uni-stuttgart.de> - 2025-01-31 12:18 +0000
Re: alarm() wird nicht ausgefiehrt Thomas Dorner <dclp250131.dorner@spamgourmet.com> - 2025-01-31 15:36 +0100
csiph-web