Test2:...ss::IPC(3pm)
π Test2::Harness::IPC β the vibe π
okay bestie, welcome to the Perl User Contributed Documentation corner of the internet, specifically the 3pm section, where we talk about Test2::Harness::IPC β¨
πΈ NAME πΈ
Test2::Harness::IPC β it's the base class for modules that control child processes. literally the mom friend of the process-management world π«Ά
π¦ DESCRIPTION π¦
So, this module is the base class for every single part of Test2::Harness that has to do process management. That's it, that's the job. It's the blueprint the other kids inherit from. π
π ATTRIBUTES π
$pid = $ipc->pidβ the root PID of the IPC object. the OG process, if you will.$hashref = $ipc->handlersβ custom signal handlers that are specific to this IPC object. your own personal signal-handling stash. π‘$hashref = $ipc->procsβ a hashref shaped like$pid => $proc, where$procis an instance ofTest2::Harness::IPC::Proc. every tracked process, filed by pid. slay.$hashref = $ipc->procs_by_catβ a hashref shaped like$category => { $pid => $proc }. same processes, but sorted into little category baskets. π§Ί$hashref = $ipc->waitingβ a hashref of the processes that have finished but haven't been handled yet. like a group chat of messages you haven't opened.
β οΈ bestie, this is an implementation detail and you should not rely on it. admiring from afar only. π
$float = $ipc->wait_timeβ how long to sleep between loops when you're in a wait cycle. nap length, basically. π΄$bool = $ipc->startedβ true if the IPC process has started. false if it's still in bed.$ipc->sig_countβ implementation detail π§ it's used to break out of wait loops whenever signals show up.
π METHODS π
β¨ Lifecycle stuff β¨
$ipc->startβ starts the IPC management, which means it inserts the signal handlers. glow up initiated.$ipc->stopβ stops the IPC management, which means it removes the signal handlers. bye bestie π
π£ Signals π£
$ipc->set_sig_handler($sig, sub { ... })β sets a custom signal handler. this is the safer version oflocal %SIG{$sig}when you're doing IPC stuff. π‘οΈ
The callback gets exactly one argument: the name of the signal that was recieved.
$ipc->handle_sig($sig)β handles the specified signal. heads up: it will cause a process exit if that signal has no handler. no handler, no mercy, we're out. π
πͺ Killing things πͺ
$ipc->killall()$ipc->killall($sig)
Kills all the tracked child processes with the given signal. If you don't specify a signal, TERM is used.
π¨ this will not wait on the processes! you must call $ipc->wait() yourself afterwards. don't forget, or you'll be sitting there confused like "where did they go". π
π Loop helpers π
$ipc->check_timeoutsβ this one is a no-op on the IPC base class. it gets called on every loop of$ipc->wait. if you subclass the IPC class, you can fill this in so your processes can time out if they need to. DIY time π¨$ipc->check_for_forkβ used a lot internally to check whether this is a forked process. And if it is a forked process, the IPC object gets completely reset with no remaining internal state left over β except the signal handlers. fresh start energy, minus one thing. π±$ipc->set_proc_exit($proc, @args)β calls$proc->set_exit(@args). this is called by$ipc->wait. you can override it to add your own custom tasks for when a process exits. cute little farewell party π
β³ Waiting β³
$int = $ipc->wait()$int = $ipc->wait(%params)
Waits on processes and returns the number found. default behaviour is non-blocking.
Here are the options, bestie:
timeout => $floatβ if a blocking parameter has been provided, this can break the wait after a timeout. it usesTime::HiRes, so the timeout is in seconds with decimals. precision, we love to see it. β±οΈall => $boolβ block until ALL the processes are done. every last one.cat => $categoryβ block until at least 1 process from the category is complete.all_cat => $categoryβ block until ALL processes from the category are complete.block => $boolβ block until at least 1 process is complete.
π Watching & spawning π
$ipc->watch($proc)β adds a process to be monitored. keeping an eye on them. ποΈ$proc = $ipc->spawn($proc)$proc = $ipc->spawn(%params)
In the first form, $proc is an instance of Test2::Harness::IPC::Proc that provides spawn_params().
In the second form, these are the params you're allowed to use:
- Anything supported by
run_cmd()inTest2::Harness::Util::IPC. β¨ process_class => $CLASSβ default isTest2::Harness::IPC::Process.command => $commandβ the program command to call. this one is required, no skipping it.env_vars => { ... }β specify custom environment variables for the new process. give the baby process its own little world π
π SOURCE π
The source code repository for Test2-Harness lives at http://github.com/Test-More/Test2-Harness/. go lurk, it's iconic. β
π MAINTAINERS π
Chad Granum <exodist@cpan.org>
π AUTHORS π
Chad Granum <exodist@cpan.org>
π COPYRIGHT π
Copyright 2020 Chad Granum <exodist7@gmail.com>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://dev.perl.org/licenses/
and that's the whole page, bestie π«Ά this shipped as part of perl v5.40.1, dated 2026-05-10, in the Test2:...ss::IPC(3pm) manual. go manage some processes, you absolute icon π
β¨π
π¦ where this page comes from
- ubuntu stonking: libtest2-harness-perl 1.000172-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms