From f8925bf9b997471a2635c3319c16e8950634121f Mon Sep 17 00:00:00 2001 From: duckboy81 Date: Fri, 23 Oct 2020 15:13:22 -0500 Subject: [PATCH 1/2] Allow signal handling for Uv w/o 100% cpu usage Ref #329 --- examples/event-loop/signals.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/examples/event-loop/signals.php b/examples/event-loop/signals.php index ee7a91fa..6c10d544 100644 --- a/examples/event-loop/signals.php +++ b/examples/event-loop/signals.php @@ -9,7 +9,20 @@ Loop::onSignal(SIGINT, function () { print "Caught SIGINT, exiting..." . PHP_EOL; + + // Check for a Uv driver + if (Loop::get() instanceof Amp\Loop\UvDriver) { + + // Stop the loop + Loop::stop(); + + // Cannot exit out of a UvDriver loop here, can only stop the loop + return; + } + exit(0); }); Loop::run(); + +exit(0); From 8abb7eb953c7f4cc1ace5ea4a36a26c64f18ee27 Mon Sep 17 00:00:00 2001 From: duckboy81 Date: Fri, 23 Oct 2020 15:29:05 -0500 Subject: [PATCH 2/2] Update examples/event-loop/signals.php Hmm, looks like it still gets stuck in the loop. I tried for a couple hours to find where the loop occurs, but I didn't get anywhere. It seemed as if it was happening in due to the libuv module (it was happening after the xdebug profiler closed out). Co-authored-by: Niklas Keller --- examples/event-loop/signals.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/examples/event-loop/signals.php b/examples/event-loop/signals.php index 6c10d544..d1462faf 100644 --- a/examples/event-loop/signals.php +++ b/examples/event-loop/signals.php @@ -7,18 +7,10 @@ print "Press Ctrl+C to exit..." . PHP_EOL; -Loop::onSignal(SIGINT, function () { +Loop::onSignal(SIGINT, function ($watcherId) { print "Caught SIGINT, exiting..." . PHP_EOL; - // Check for a Uv driver - if (Loop::get() instanceof Amp\Loop\UvDriver) { - - // Stop the loop - Loop::stop(); - - // Cannot exit out of a UvDriver loop here, can only stop the loop - return; - } + Loop::cancel($watcherId); exit(0); });