New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update of perlfunc alarm() synopsis #15902
Comments
From jozef.kutej@geizhals.atHi, attached is suggestion-patch for alarm() synopsis. The current version by "local $SIG{ALRM}" implies that the previous SIGALARM functionality is restored. But it fact if will never by fired because of the timer it self not restored. Proposed version should point out this fact and demonstrate the possible usage of alarm() return value too. Best regards -- Jozef Kutej Geizhals (R) - Preisvergleich http://www.geizhals.at | http://www.geizhals.de | http://www.geizhals.eu Handelsgericht Wien | FN 197241K | Firmensitz Wien |
From jozef.kutej@geizhals.atalarm-synopsis.patchdiff --git a/cpan/Pod-Perldoc/corpus/perlfunc.pod b/cpan/Pod-Perldoc/corpus/perlfunc.pod
index 604123daf8..d06fb50e31 100644
--- a/cpan/Pod-Perldoc/corpus/perlfunc.pod
+++ b/cpan/Pod-Perldoc/corpus/perlfunc.pod
@@ -497,11 +497,12 @@ fail with C<$!> set to C<EINTR> because Perl sets up signal handlers to
restart system calls on some systems. Using C<eval>/C<die> always works,
modulo the caveats given in L<perlipc/"Signals">.
+ my $timeout = 10;
eval {
- local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
- alarm $timeout;
- $nread = sysread SOCKET, $buffer, $size;
- alarm 0;
+ my $previous_timeout = alarm $timeout;
+ local $SIG{ALRM} = sub { alarm $previous_timeout; die "alarm\n" }; # NB: \n required
+ my $nread = sysread $socket, $buffer, $size;
+ alarm $previous_timeout;
};
if ($@) {
die unless $@ eq "alarm\n"; # propagate unexpected errors
diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod
index 3854acf6e6..d7d5922678 100644
--- a/pod/perlfunc.pod
+++ b/pod/perlfunc.pod
@@ -732,11 +732,12 @@ to restart system calls on some systems. Using
L<C<eval>|/eval EXPR>/L<C<die>|/die LIST> always works, modulo the
caveats given in L<perlipc/"Signals">.
+ my $timeout = 10;
eval {
- local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
- alarm $timeout;
+ my $previous_timeout = alarm $timeout;
+ local $SIG{ALRM} = sub { alarm $previous_timeout; die "alarm\n" }; # NB: \n required
my $nread = sysread $socket, $buffer, $size;
- alarm 0;
+ alarm $previous_timeout;
};
if ($@) {
die unless $@ eq "alarm\n"; # propagate unexpected errors
|
From @LeontOn Thu, Mar 2, 2017 at 2:54 PM, Jozef Kutej <perlbug-followup@perl.org> wrote:
Why would you want to set the alarm to some previous value it had at Leon |
The RT System itself - Status changed from 'new' to 'open' |
From @jkeenanOn Thu, 02 Mar 2017 13:54:25 GMT, jozef.kutej@geizhals.at wrote:
The patch provided calls for modifications to pod/perlfunc.pod and to a file in the Pod-Perldoc distribution. The latter is maintained upstream on CPAN. I am cc-ing the maintainer of that distribution for comments before proceeding. Thank you very much. -- |
From @demerphqOn 2 March 2017 at 18:16, Leon Timmermans <fawaka@gmail.com> wrote:
There is only one alarm timer per process. A well behaved user of alarm will capture the return from their own See Time::Out on cpan for an example of this pattern. Something like this: $remaining= alarm(0); But more complicated. If you check the code in Time::Out it is not Yves -- |
From @LeontOn Thu, Jun 1, 2017 at 5:06 PM, demerphq <demerphq@gmail.com> wrote:
Yes I fully realize there can only be one alarm timer per process, I didn't A well behaved user of alarm will capture the return from their own
I don't quite think Time::Out is entirely correct either (e.g. it's not In all other cases there are better approaches to this; the example is Leon |
From @demerphqOn 2 June 2017 at 02:55, Leon Timmermans <fawaka@gmail.com> wrote:
I don't think people who use alarm use threads. None of our work
Well its still better than nothing.
For that you are probably better using a watchdog type functionality.
Yeah well exactly. We use alarm() to timeout our web-requests, and we use alarm() to time So we end up using the Time::Out pattern. (Except I hacked it to I personally think that documenting all of this is important. Yves |
From @LeontOn Thu, Jun 1, 2017 at 4:24 PM, James E Keenan via RT <
The latter is a copy of the former for testing purposes. Leon |
From @mrallen1On Thu, 01 Jun 2017 07:24:14 -0700, jkeenan wrote:
As Leon noted before, the file in Pod-Perldoc is a copy for testing purposes only. |
Migrated from rt.perl.org#130902 (status was 'open')
Searchable as RT130902$
The text was updated successfully, but these errors were encountered: