ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent.pm (file contents):
Revision 1.246 by root, Sat Jul 18 15:51:52 2009 UTC vs.
Revision 1.247 by root, Sat Jul 18 22:24:17 2009 UTC

368 368
369This watcher might use C<%SIG> (depending on the event loop used), 369This watcher might use C<%SIG> (depending on the event loop used),
370so programs overwriting those signals directly will likely not work 370so programs overwriting those signals directly will likely not work
371correctly. 371correctly.
372 372
373Example: exit on SIGINT
374
375 my $w = AnyEvent->signal (signal => "INT", cb => sub { exit 1 });
376
377=head3 Signal Races, Delays and Workarounds
378
373Also note that many event loops (e.g. Glib, Tk, Qt, IO::Async) do not 379Many event loops (e.g. Glib, Tk, Qt, IO::Async) do not support attaching
374support attaching callbacks to signals, which is a pity, as you cannot do 380callbacks to signals in a generic way, which is a pity, as you cannot do
375race-free signal handling in perl. AnyEvent will try to do it's best, but 381race-free signal handling in perl. AnyEvent will try to do it's best, but
376in some cases, signals will be delayed. The maximum time a signal might 382in some cases, signals will be delayed. The maximum time a signal might
377be delayed is specified in C<$AnyEvent::MAX_SIGNAL_LATENCY> (default: 10 383be delayed is specified in C<$AnyEvent::MAX_SIGNAL_LATENCY> (default: 10
378seconds). This variable can be changed only before the first signal 384seconds). This variable can be changed only before the first signal
379watcher is created, and should be left alone otherwise. Higher values 385watcher is created, and should be left alone otherwise. Higher values
380will cause fewer spurious wake-ups, which is better for power and CPU 386will cause fewer spurious wake-ups, which is better for power and CPU
381saving. All these problems can be avoided by installing the optional 387saving. All these problems can be avoided by installing the optional
382L<Async::Interrupt> module. 388L<Async::Interrupt> module. This will not work with inherently broken
383 389event loops such as L<Event> or L<Event::Lib> (and not with L<POE>
384Example: exit on SIGINT 390currently, as POE does it's own workaround with one-second latency). With
385 391those, you just have to suffer the delays.
386 my $w = AnyEvent->signal (signal => "INT", cb => sub { exit 1 });
387 392
388=head2 CHILD PROCESS WATCHERS 393=head2 CHILD PROCESS WATCHERS
389 394
390You can also watch on a child process exit and catch its exit status. 395You can also watch on a child process exit and catch its exit status.
391 396
2270 2275
2271This slightly arcane module is used to implement fast signal handling: To 2276This slightly arcane module is used to implement fast signal handling: To
2272my knowledge, there is no way to do completely race-free and quick 2277my knowledge, there is no way to do completely race-free and quick
2273signal handling in pure perl. To ensure that signals still get 2278signal handling in pure perl. To ensure that signals still get
2274delivered, AnyEvent will start an interval timer to wake up perl (and 2279delivered, AnyEvent will start an interval timer to wake up perl (and
2275catch the signals) with soemd elay (default is 10 seconds, look for 2280catch the signals) with some delay (default is 10 seconds, look for
2276C<$AnyEvent::MAX_SIGNAL_LATENCY>). 2281C<$AnyEvent::MAX_SIGNAL_LATENCY>).
2277 2282
2278If this module is available, then it will be used to implement signal 2283If this module is available, then it will be used to implement signal
2279catching, which means that signals will not be delayed, and the event loop 2284catching, which means that signals will not be delayed, and the event loop
2280will not be interrupted regularly, which is more efficient (And good for 2285will not be interrupted regularly, which is more efficient (And good for
2281battery life on laptops). 2286battery life on laptops).
2282 2287
2283This affects not just the pure-perl event loop, but also other event loops 2288This affects not just the pure-perl event loop, but also other event loops
2284that have no signal handling on their own (e.g. Glib, Tk, Qt). 2289that have no signal handling on their own (e.g. Glib, Tk, Qt).
2290
2291Some event loops (POE, Event, Event::Lib) offer signal watchers natively,
2292and either employ their own workarounds (POE) or use AnyEvent's workaround
2293(using C<$AnyEvent::MAX_SIGNAL_LATENCY>). Installing L<Async::Interrupt>
2294does nothing for those backends.
2285 2295
2286=item L<EV> 2296=item L<EV>
2287 2297
2288This module isn't really "optional", as it is simply one of the backend 2298This module isn't really "optional", as it is simply one of the backend
2289event loops that AnyEvent can use. However, it is simply the best event 2299event loops that AnyEvent can use. However, it is simply the best event

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines