Why do I get "POE::Kernel's run() method was never called" when I try to run my POE program as a daemon?

This message occurs when a POE::Session is started, but the program exits before POE::Kernel->run() has been called. It's displayed at the time POE::Kernel is destroyed, which is shortly before a process exits.

This mostly happens in daemons, in tests, and in programs that have crashed during setup.

One way to solve the issue is to call POE::Kernel->run() first, even before starting a POE::Session. run() returns right away because there are no active sessions. It also sets the "run was called" flag. Now you're free to fork, exit, or crash without the warning.

A second workaround is exclusive to daemons: Daemonize before starting any sessions. The warning is only displayed if a session was created but never had the opportunity to run. If no sessions are created before the fork(), then no warning is issued.

A third option is to use POSIX::_exit() rather than the built-in exit() to exit a program. POSIX's _exit() bypasses object destruction entirely, and POE::Kernel's DESTROY method will not have a chance to check whether run() was called.

A fourth, general solution, is to break encapsulation and modify the "run was called" flag yourself. This will silence the warning at the cost of your immortal soul. Therefore we neither recommend nor support this method. Depending on the version of POE, the code may or may not be:

  ${$poe_kernel->[POE::Kernel::KR_RUN]} |= POE::Kernel::KR_RUN_CALLED;