--- AnyEvent/README 2011/08/21 03:02:32 1.66 +++ AnyEvent/README 2019/02/26 02:08:34 1.79 @@ -1,8 +1,9 @@ NAME AnyEvent - the DBI of event loop programming - EV, Event, Glib, Tk, Perl, Event::Lib, Irssi, rxvt-unicode, IO::Async, - Qt, FLTK and POE are various supported event loops/environments. + EV, Event, Glib, Tk, UV, Perl, Event::Lib, Irssi, rxvt-unicode, + IO::Async, Qt, FLTK and POE are various supported event + loops/environments. SYNOPSIS use AnyEvent; @@ -264,7 +265,7 @@ my $w = AnyEvent->timer (after => 0.5, interval => 1, cb => sub { warn "timeout\n"; - }; + }); TIMING ISSUES There are two ways to handle timers: based on real time (relative, "fire @@ -405,8 +406,8 @@ Safe/Unsafe Signals Perl signals can be either "safe" (synchronous to opcode handling) or - "unsafe" (asynchronous) - the former might get delayed indefinitely, the - latter might corrupt your memory. + "unsafe" (asynchronous) - the former might delay signal delivery + indefinitely, the latter might corrupt your memory. AnyEvent signal handlers are, in addition, synchronous to the event loop, i.e. they will not interrupt your running perl program but will @@ -418,19 +419,15 @@ callbacks to signals in a generic way, which is a pity, as you cannot do race-free signal handling in perl, requiring C libraries for this. AnyEvent will try to do its best, which means in some cases, signals - will be delayed. The maximum time a signal might be delayed is specified - in $AnyEvent::MAX_SIGNAL_LATENCY (default: 10 seconds). This variable - can be changed only before the first signal watcher is created, and - should be left alone otherwise. This variable determines how often - AnyEvent polls for signals (in case a wake-up was missed). Higher values - will cause fewer spurious wake-ups, which is better for power and CPU - saving. + will be delayed. The maximum time a signal might be delayed is 10 + seconds by default, but can be overriden via + $ENV{PERL_ANYEVENT_MAX_SIGNAL_LATENCY} or $AnyEvent::MAX_SIGNAL_LATENCY + - see the "ENVIRONMENT VARIABLES" section for details. All these problems can be avoided by installing the optional Async::Interrupt module, which works with most event loops. It will not work with inherently broken event loops such as Event or Event::Lib (and - not with POE currently, as POE does its own workaround with one-second - latency). For those, you just have to suffer the delays. + not with POE currently). For those, you just have to suffer the delays. CHILD PROCESS WATCHERS $w = AnyEvent->child (pid => , cb => ); @@ -475,6 +472,10 @@ my $done = AnyEvent->condvar; + # this forks and immediately calls exit in the child. this + # normally has all sorts of bad consequences for your parent, + # so take this as an example only. always fork and exec, + # or call POSIX::_exit, in real code. my $pid = fork or exit 5; my $w = AnyEvent->child ( @@ -724,7 +725,7 @@ "end" before sending. The ping example mentioned above is slightly more complicated, as - the there are results to be passwd back, and the number of tasks + the there are results to be passed back, and the number of tasks that are begun can potentially be zero: my $cv = AnyEvent->condvar; @@ -742,6 +743,10 @@ $cv->end; + ... + + my $results = $cv->recv; + This code fragment supposedly pings a number of hosts and calls "send" after results for all then have have been gathered - in any order. To achieve this, the code issues a call to "begin" when it @@ -780,10 +785,15 @@ Note that doing a blocking wait in a callback is not supported by any event loop, that is, recursive invocation of a blocking "->recv" - is not allowed, and the "recv" call will "croak" if such a condition - is detected. This condition can be slightly loosened by using - Coro::AnyEvent, which allows you to do a blocking "->recv" from any - thread that doesn't run the event loop itself. + is not allowed and the "recv" call will "croak" if such a condition + is detected. This requirement can be dropped by relying on + Coro::AnyEvent , which allows you to do a blocking "->recv" from any + thread that doesn't run the event loop itself. Coro::AnyEvent is + loaded automatically when Coro is used with AnyEvent, so code does + not need to do anything special to take advantage of that: any code + that would normally block your program because it calls "recv", be + executed in an "async" thread instead without blocking other + threads. Not all event models support a blocking wait - some die in that case (programs might want to do that to stay interactive), so *if you are @@ -804,8 +814,8 @@ "croak" have been called. $cb = $cv->cb ($cb->($cv)) - This is a mutator function that returns the callback set and - optionally replaces it before doing so. + This is a mutator function that returns the callback set (or "undef" + if not) and optionally replaces it before doing so. The callback will be called when the condition becomes "true", i.e. when "send" or "croak" are called, with the only argument being the @@ -813,8 +823,13 @@ callback is called immediately when it is set. Calling "recv" inside the callback or at any later time is guaranteed not to block. + Additionally, when the callback is invoked, it is also removed from + the condvar (reset to "undef"), so the condvar does not keep a + reference to the callback after invocation. + SUPPORTED EVENT LOOPS/BACKENDS - The available backend classes are (every class has its own manpage): + The following backend classes are part of the AnyEvent distribution + (every class has its own manpage): Backends that are autoprobed when no other event loop can be found. EV is the preferred backend when no other event loop seems to be in @@ -836,12 +851,13 @@ AnyEvent::Impl::Event based on Event, very stable, few glitches. AnyEvent::Impl::Glib based on Glib, slow but very stable. AnyEvent::Impl::Tk based on Tk, very broken. + AnyEvent::Impl::UV based on UV, innovated square wheels. AnyEvent::Impl::EventLib based on Event::Lib, leaks memory and worse. AnyEvent::Impl::POE based on POE, very slow, some limitations. AnyEvent::Impl::Irssi used when running within irssi. AnyEvent::Impl::IOAsync based on IO::Async. AnyEvent::Impl::Cocoa based on Cocoa::EventLoop. - AnyEvent::Impl::FLTK2 based on FLTK (fltk 2 binding). + AnyEvent::Impl::FLTK based on FLTK (fltk 2 binding). Backends with special needs. Qt requires the Qt::Application to be instantiated first, but will @@ -868,6 +884,12 @@ load POE when detecting them, in the hope that POE will pick them up, in which case everything will be automatic. + Known event loops outside the AnyEvent distribution + The following event loops or programs support AnyEvent by providing + their own AnyEvent backend. They will be picked up automatically. + + urxvt::anyevent available to rxvt-unicode extensions + GLOBAL VARIABLES AND FUNCTIONS These are not normally required to use AnyEvent, but can be useful to write AnyEvent extension modules. @@ -901,13 +923,12 @@ model is autodetected (or immediately if that has already happened). The block will be executed *after* the actual backend has been - detected ($AnyEvent::MODEL is set), but *before* any watchers have - been created, so it is possible to e.g. patch @AnyEvent::ISA or do - other initialisations - see the sources of AnyEvent::Strict or - AnyEvent::AIO to see how this is used. + detected ($AnyEvent::MODEL is set), so it is possible to do some + initialisation only when AnyEvent is actually initialised - see the + sources of AnyEvent::AIO to see how this is used. The most common usage is to create some global watchers, without - forcing event module detection too early, for example, AnyEvent::AIO + forcing event module detection too early. For example, AnyEvent::AIO creates and installs the global IO::AIO watcher in a "post_detect" block to avoid autodetecting the event module at load time. @@ -933,9 +954,16 @@ $WATCHER ||= $guard; @AnyEvent::post_detect - If there are any code references in this array (you can "push" to it - before or after loading AnyEvent), then they will be called directly - after the event loop has been chosen. + This is a lower level interface then "AnyEvent::post_detect" (the + function). This variable is mainly useful for modules that can do + something useful when AnyEvent is used and thus want to know when it + is initialised, but do not need to even load it by default. This + array provides the means to hook into AnyEvent passively, without + loading it. + + Here is how it works: If there are any code references in this array + (you can "push" to it before or after loading AnyEvent), then they + will be called directly after the event loop has been chosen. You should check $AnyEvent::MODEL before adding to this array, though: if it is defined then the event loop has already been @@ -944,12 +972,6 @@ Best use "AnyEvent::post_detect { BLOCK }" when your application allows it, as it takes care of these details. - This variable is mainly useful for modules that can do something - useful when AnyEvent is used and thus want to know when it is - initialised, but do not need to even load it by default. This array - provides the means to hook into AnyEvent passively, without loading - it. - Example: To load Coro::AnyEvent whenever Coro and AnyEvent are used together, you could put this into Coro (this is the actual code used by Coro to accomplish this): @@ -977,7 +999,7 @@ transaction object or guard to let you cancel the operation. For example, "AnyEvent::Socket::tcp_connect": - # start a conenction attempt unless one is active + # start a connection attempt unless one is active $self->{connect_guard} ||= AnyEvent::Socket::tcp_connect "www.example.net", 80, sub { delete $self->{connect_guard}; ... @@ -1007,12 +1029,23 @@ AnyEvent::log $level, $msg[, @args] Log the given $msg at the given $level. - Loads AnyEvent::Log on first use and calls "AnyEvent::Log::log" - + If AnyEvent::Log is not loaded then this function makes a simple + test to see whether the message will be logged. If the test succeeds + it will load AnyEvent::Log and call "AnyEvent::Log::log" - consequently, look at the AnyEvent::Log documentation for details. + If the test fails it will simply return. Right now this happens when + a numerical loglevel is used and it is larger than the level + specified via $ENV{PERL_ANYEVENT_VERBOSE}. + If you want to sprinkle loads of logging calls around your code, consider creating a logger callback with the "AnyEvent::Log::logger" - function. + function, which can reduce typing, codesize and can reduce the + logging overhead enourmously. + + AnyEvent::fh_block $filehandle + AnyEvent::fh_unblock $filehandle + Sets blocking or non-blocking behaviour for the given filehandle. WHAT TO DO IN A MODULE As a module author, you should "use AnyEvent" and call AnyEvent methods @@ -1081,22 +1114,22 @@ non-exhaustive list), and the list is heavily biased towards modules of the AnyEvent author himself :) - AnyEvent::Util + AnyEvent::Util (part of the AnyEvent distribution) Contains various utility functions that replace often-used blocking functions such as "inet_aton" with event/callback-based versions. - AnyEvent::Socket + AnyEvent::Socket (part of the AnyEvent distribution) Provides various utility functions for (internet protocol) sockets, addresses and name resolution. Also functions to create non-blocking tcp connections or tcp servers, with IPv6 and SRV record support and more. - AnyEvent::Handle + AnyEvent::Handle (part of the AnyEvent distribution) Provide read and write buffers, manages watchers for reads and writes, supports raw and formatted I/O, I/O queued and fully transparent and non-blocking SSL/TLS (via AnyEvent::TLS). - AnyEvent::DNS + AnyEvent::DNS (part of the AnyEvent distribution) Provides rich asynchronous DNS resolver capabilities. AnyEvent::HTTP, AnyEvent::IRC, AnyEvent::XMPP, AnyEvent::GPSD, @@ -1105,41 +1138,59 @@ (for the curious, IGS is the International Go Server and FCP is the Freenet Client Protocol). - AnyEvent::Handle::UDP - Here be danger! - - As Pauli would put it, "Not only is it not right, it's not even - wrong!" - there are so many things wrong with AnyEvent::Handle::UDP, - most notably its use of a stream-based API with a protocol that - isn't streamable, that the only way to improve it is to delete it. - - It features data corruption (but typically only under load) and - general confusion. On top, the author is not only clueless about UDP - but also fact-resistant - some gems of his understanding: "connect - doesn't work with UDP", "UDP packets are not IP packets", "UDP only - has datagrams, not packets", "I don't need to implement proper error - checking as UDP doesn't support error checking" and so on - he - doesn't even understand what's wrong with his module when it is - explained to him. - - AnyEvent::DBI - Executes DBI requests asynchronously in a proxy process for you, - notifying you in an event-based way when the operation is finished. - - AnyEvent::AIO + AnyEvent::AIO (part of the AnyEvent distribution) Truly asynchronous (as opposed to non-blocking) I/O, should be in the toolbox of every event programmer. AnyEvent::AIO transparently fuses IO::AIO and AnyEvent together, giving AnyEvent access to event-based file I/O, and much more. - AnyEvent::HTTPD - A simple embedded webserver. + AnyEvent::Fork, AnyEvent::Fork::RPC, AnyEvent::Fork::Pool, + AnyEvent::Fork::Remote + These let you safely fork new subprocesses, either locally or + remotely (e.g.v ia ssh), using some RPC protocol or not, without the + limitations normally imposed by fork (AnyEvent works fine for + example). Dynamically-resized worker pools are obviously included as + well. + + And they are quite tiny and fast as well - "abusing" AnyEvent::Fork + just to exec external programs can easily beat using "fork" and + "exec" (or even "system") in most programs. + + AnyEvent::Filesys::Notify + AnyEvent is good for non-blocking stuff, but it can't detect file or + path changes (e.g. "watch this directory for new files", "watch this + file for changes"). The AnyEvent::Filesys::Notify module promises to + do just that in a portbale fashion, supporting inotify on GNU/Linux + and some weird, without doubt broken, stuff on OS X to monitor + files. It can fall back to blocking scans at regular intervals + transparently on other platforms, so it's about as portable as it + gets. + + (I haven't used it myself, but it seems the biggest problem with it + is it quite bad performance). + + AnyEvent::DBI + Executes DBI requests asynchronously in a proxy process for you, + notifying you in an event-based way when the operation is finished. AnyEvent::FastPing The fastest ping in the west. Coro - Has special support for AnyEvent via Coro::AnyEvent. + Has special support for AnyEvent via Coro::AnyEvent, which allows + you to simply invert the flow control - don't call us, we will call + you: + + async { + Coro::AnyEvent::sleep 5; # creates a 5s timer and waits for it + print "5 seconds later!\n"; + + Coro::AnyEvent::readable *STDIN; # uses an I/O watcher + my $line = ; # works for ttys + + AnyEvent::HTTP::http_get "url", Coro::rouse_cb; + my ($body, $hdr) = Coro::rouse_wait; + }; SIMPLIFIED AE API Starting with version 5.0, AnyEvent officially supports a second, much @@ -1165,28 +1216,86 @@ Glib uses "install_exception_handler" and so on. ENVIRONMENT VARIABLES - The following environment variables are used by this module or its - submodules. + AnyEvent supports a number of environment variables that tune the + runtime behaviour. They are usually evaluated when AnyEvent is loaded, + initialised, or a submodule that uses them is loaded. Many of them also + cause AnyEvent to load additional modules - for example, + "PERL_ANYEVENT_DEBUG_WRAP" causes the AnyEvent::Debug module to be + loaded. - Note that AnyEvent will remove *all* environment variables starting with - "PERL_ANYEVENT_" from %ENV when it is loaded while taint mode is - enabled. + All the environment variables documented here start with + "PERL_ANYEVENT_", which is what AnyEvent considers its own namespace. + Other modules are encouraged (but by no means required) to use + "PERL_ANYEVENT_SUBMODULE" if they have registered the + AnyEvent::Submodule namespace on CPAN, for any submodule. For example, + AnyEvent::HTTP could be expected to use "PERL_ANYEVENT_HTTP_PROXY" (it + should not access env variables starting with "AE_", see below). + + All variables can also be set via the "AE_" prefix, that is, instead of + setting "PERL_ANYEVENT_VERBOSE" you can also set "AE_VERBOSE". In case + there is a clash btween anyevent and another program that uses + "AE_something" you can set the corresponding "PERL_ANYEVENT_something" + variable to the empty string, as those variables take precedence. + + When AnyEvent is first loaded, it copies all "AE_xxx" env variables to + their "PERL_ANYEVENT_xxx" counterpart unless that variable already + exists. If taint mode is on, then AnyEvent will remove *all* environment + variables starting with "PERL_ANYEVENT_" from %ENV (or replace them with + "undef" or the empty string, if the corresaponding "AE_" variable is + set). + + The exact algorithm is currently: + + 1. if taint mode enabled, delete all PERL_ANYEVENT_xyz variables from %ENV + 2. copy over AE_xyz to PERL_ANYEVENT_xyz unless the latter alraedy exists + 3. if taint mode enabled, set all PERL_ANYEVENT_xyz variables to undef. + + This ensures that child processes will not see the "AE_" variables. + + The following environment variables are currently known to AnyEvent: "PERL_ANYEVENT_VERBOSE" - By default, AnyEvent will be completely silent except in fatal - conditions. You can set this environment variable to make AnyEvent - more talkative. + By default, AnyEvent will log messages with loglevel 4 ("error") or + higher (see AnyEvent::Log). You can set this environment variable to + a numerical loglevel to make AnyEvent more (or less) talkative. + + If you want to do more than just set the global logging level you + should have a look at "PERL_ANYEVENT_LOG", which allows much more + complex specifications. - When set to 5 or higher, causes AnyEvent to warn about unexpected + When set to 0 ("off"), then no messages whatsoever will be logged + with everything else at defaults. + + When set to 5 or higher ("warn"), AnyEvent warns about unexpected conditions, such as not being able to load the event model specified - by "PERL_ANYEVENT_MODEL". + by "PERL_ANYEVENT_MODEL", or a guard callback throwing an exception + - this is the minimum recommended level for use during development. - When set to 7 or higher, cause AnyEvent to report to STDERR which - event model it chooses. + When set to 7 or higher (info), AnyEvent reports which event model + it chooses. - When set to 8 or higher, then AnyEvent will report extra information - on which optional modules it loads and how it implements certain - features. + When set to 8 or higher (debug), then AnyEvent will report extra + information on which optional modules it loads and how it implements + certain features. + + "PERL_ANYEVENT_LOG" + Accepts rather complex logging specifications. For example, you + could log all "debug" messages of some module to stderr, warnings + and above to stderr, and errors and above to syslog, with: + + PERL_ANYEVENT_LOG=Some::Module=debug,+log:filter=warn,+%syslog:%syslog=error,syslog + + For the rather extensive details, see AnyEvent::Log. + + This variable is evaluated when AnyEvent (or AnyEvent::Log) is + loaded, so will take effect even before AnyEvent has initialised + itself. + + Note that specifying this environment variable causes the + AnyEvent::Log module to be loaded, while "PERL_ANYEVENT_VERBOSE" + does not, so only using the latter saves a few hundred kB of memory + unless a module explicitly needs the extra features of + AnyEvent::Log. "PERL_ANYEVENT_STRICT" AnyEvent does not do much argument checking by default, as thorough @@ -1203,21 +1312,27 @@ programs can be very useful, however. "PERL_ANYEVENT_DEBUG_SHELL" - If this env variable is set, then its contents will be interpreted - by "AnyEvent::Socket::parse_hostport" (after replacing every - occurance of $$ by the process pid) and an "AnyEvent::Debug::shell" - is bound on that port. The shell object is saved in + If this env variable is nonempty, then its contents will be + interpreted by "AnyEvent::Socket::parse_hostport" and + "AnyEvent::Debug::shell" (after replacing every occurance of $$ by + the process pid). The shell object is saved in $AnyEvent::Debug::SHELL. - This takes place when the first watcher is created. + This happens when the first watcher is created. For example, to bind a debug shell on a unix domain socket in /tmp/debug.sock, you could use this: PERL_ANYEVENT_DEBUG_SHELL=/tmp/debug\$\$.sock perlprog + # connect with e.g.: socat readline /tmp/debug123.sock + + Or to bind to tcp port 4545 on localhost: - Note that creating sockets in /tmp is very unsafe on multiuser - systems. + PERL_ANYEVENT_DEBUG_SHELL=127.0.0.1:4545 perlprog + # connect with e.g.: telnet localhost 4545 + + Note that creating sockets in /tmp or on localhost is very unsafe on + multiuser systems. "PERL_ANYEVENT_DEBUG_WRAP" Can be set to 0, 1 or 2 and enables wrapping of all watchers for @@ -1243,6 +1358,13 @@ PERL_ANYEVENT_MODEL=Perl perl ... + "PERL_ANYEVENT_IO_MODEL" + The current file I/O model - see AnyEvent::IO for more info. + + At the moment, only "Perl" (small, pure-perl, synchronous) and + "IOAIO" (truly asynchronous) are supported. The default is "IOAIO" + if AnyEvent::AIO can be loaded, otherwise it is "Perl". + "PERL_ANYEVENT_PROTOCOLS" Used by both AnyEvent::DNS and AnyEvent::Socket to determine preferences for IPv4 or IPv6. The default is unspecified (and might @@ -1255,7 +1377,7 @@ This variable can effectively be used for denial-of-service attacks against local programs (e.g. when setuid), although the impact is - likely small, as the program has to handle conenction and other + likely small, as the program has to handle connection and other failures anyways. Examples: "PERL_ANYEVENT_PROTOCOLS=ipv4,ipv6" - prefer IPv4 over @@ -1265,11 +1387,16 @@ "PERL_ANYEVENT_PROTOCOLS=ipv6,ipv4" support either IPv4 or IPv6, but prefer IPv6 over IPv4. + "PERL_ANYEVENT_HOSTS" + This variable, if specified, overrides the /etc/hosts file used by + AnyEvent::Socket"::resolve_sockaddr", i.e. hosts aliases will be + read from that file instead. + "PERL_ANYEVENT_EDNS0" Used by AnyEvent::DNS to decide whether to use the EDNS0 extension for DNS. This extension is generally useful to reduce DNS traffic, - but some (broken) firewalls drop such DNS packets, which is why it - is off by default. + especially when DNSSEC is involved, but some (broken) firewalls drop + such DNS packets, which is why it is off by default. Setting this variable to 1 will cause AnyEvent::DNS to announce EDNS0 in its DNS requests. @@ -1283,15 +1410,36 @@ default DNS resolver - this is the maximum number of parallel DNS requests that are sent to the DNS server. + "PERL_ANYEVENT_MAX_SIGNAL_LATENCY" + Perl has inherently racy signal handling (you can basically choose + between losing signals and memory corruption) - pure perl event + loops (including "AnyEvent::Loop", when "Async::Interrupt" isn't + available) therefore have to poll regularly to avoid losing signals. + + Some event loops are racy, but don't poll regularly, and some event + loops are written in C but are still racy. For those event loops, + AnyEvent installs a timer that regularly wakes up the event loop. + + By default, the interval for this timer is 10 seconds, but you can + override this delay with this environment variable (or by setting + the $AnyEvent::MAX_SIGNAL_LATENCY variable before creating signal + watchers). + + Lower values increase CPU (and energy) usage, higher values can + introduce long delays when reaping children or waiting for signals. + + The AnyEvent::Async module, if available, will be used to avoid this + polling (with most event loops). + "PERL_ANYEVENT_RESOLV_CONF" - The file to use instead of /etc/resolv.conf (or OS-specific - configuration) in the default resolver. When set to the empty - string, no default config will be used. + The absolute path to a resolv.conf-style file to use instead of + /etc/resolv.conf (or the OS-specific configuration) in the default + resolver, or the empty string to select the default configuration. "PERL_ANYEVENT_CA_FILE", "PERL_ANYEVENT_CA_PATH". When neither "ca_file" nor "ca_path" was specified during AnyEvent::TLS context creation, and either of these environment - variables exist, they will be used to specify CA certificate + variables are nonempty, they will be used to specify CA certificate locations instead of a system-dependent default. "PERL_ANYEVENT_AVOID_GUARD" and "PERL_ANYEVENT_AVOID_ASYNC_INTERRUPT" @@ -1473,7 +1621,7 @@ ... }); - EV::loop; + EV::run; 3b. The module user could use AnyEvent, too: @@ -1894,6 +2042,15 @@ its own. The pure-perl event loop (AnyEvent::Loop) will additionally load it to try to use a monotonic clock for timing stability. + AnyEvent::AIO (and IO::AIO) + The default implementation of AnyEvent::IO is to do I/O + synchronously, stopping programs while they access the disk, which + is fine for a lot of programs. + + Installing AnyEvent::AIO (and its IO::AIO dependency) makes it + switch to a true asynchronous implementation, so event processing + can continue even while waiting for disk I/O. + FORK Most event libraries are not fork-safe. The ones who are usually are because they rely on inefficient but fork-safe "select" or "poll" calls @@ -1910,17 +2067,34 @@ If you have to fork, you must either do so *before* creating your first watcher OR you must not use AnyEvent at all in the child OR you must do - something completely out of the scope of AnyEvent. + something completely out of the scope of AnyEvent (see below). The problem of doing event processing in the parent *and* the child is much more complicated: even for backends that *are* fork-aware or fork-safe, their behaviour is not usually what you want: fork clones all watchers, that means all timers, I/O watchers etc. are active in both - parent and child, which is almost never what you want. USing "exec" to - start worker children from some kind of manage rprocess is usually + parent and child, which is almost never what you want. Using "exec" to + start worker children from some kind of manage prrocess is usually preferred, because it is much easier and cleaner, at the expense of having to have another binary. + In addition to logical problems with fork, there are also implementation + problems. For example, on POSIX systems, you cannot fork at all in Perl + code if a thread (I am talking of pthreads here) was ever created in the + process, and this is just the tip of the iceberg. In general, using fork + from Perl is difficult, and attempting to use fork without an exec to + implement some kind of parallel processing is almost certainly doomed. + + To safely fork and exec, you should use a module such as Proc::FastSpawn + that let's you safely fork and exec new processes. + + If you want to do multiprocessing using processes, you can look at the + AnyEvent::Fork module (and some related modules such as + AnyEvent::Fork::RPC, AnyEvent::Fork::Pool and AnyEvent::Fork::Remote). + This module allows you to safely create subprocesses without any + limitations - you can use X11 toolkits or AnyEvent in the children + created by AnyEvent::Fork safely and without any special precautions. + SECURITY CONSIDERATIONS AnyEvent can be forced to load any event model via $ENV{PERL_ANYEVENT_MODEL}. While this cannot (to my knowledge) be used @@ -1964,16 +2138,19 @@ AnyEvent::Debug (interactive shell, watcher tracing). Supported event modules: AnyEvent::Loop, EV, EV::Glib, Glib::EV, Event, - Glib::Event, Glib, Tk, Event::Lib, Qt, POE, FLTK. + Glib::Event, Glib, Tk, Event::Lib, Qt, POE, FLTK, Cocoa::EventLoop, UV. Implementations: AnyEvent::Impl::EV, AnyEvent::Impl::Event, AnyEvent::Impl::Glib, AnyEvent::Impl::Tk, AnyEvent::Impl::Perl, AnyEvent::Impl::EventLib, AnyEvent::Impl::Qt, AnyEvent::Impl::POE, - AnyEvent::Impl::IOAsync, Anyevent::Impl::Irssi, AnyEvent::Impl::FLTK. + AnyEvent::Impl::IOAsync, AnyEvent::Impl::Irssi, AnyEvent::Impl::FLTK, + AnyEvent::Impl::Cocoa, AnyEvent::Impl::UV. Non-blocking handles, pipes, stream sockets, TCP clients and servers: AnyEvent::Handle, AnyEvent::Socket, AnyEvent::TLS. + Asynchronous File I/O: AnyEvent::IO. + Asynchronous DNS: AnyEvent::DNS. Thread support: Coro, Coro::AnyEvent, Coro::EV, Coro::Event. @@ -1983,5 +2160,5 @@ AUTHOR Marc Lehmann - http://home.schmorp.de/ + http://anyevent.schmorp.de