amphp / parallel

An advanced parallelization library for PHP, enabling efficient multitasking, optimizing resource use, and application responsiveness through multiple CPU threads.
MIT License
789 stars 63 forks source link

ContextException: Starting the process failed #119

Closed enumag closed 1 year ago

enumag commented 4 years ago

Lately I'm getting this error when using amphp/parallel. When I check the previous exception it is

Amp\Parallel\Context\ContextException: Starting the process timed out.

Any idea what could be wrong here and how to fix it?

enumag commented 4 years ago

I tried to wrap the yield enqueue($task); call in a loop, catching the exception and retry on failure. With that I'm getting this:

User Warning: Worker in pool crashed with exception on shutdown: User Warning: Worker in pool exited unexpectedly with code -1
enumag commented 4 years ago

I tried with both uv and native driver, same result.

enumag commented 4 years ago

The issue disappeared when I removed xdebug. :thinking:

trowski commented 4 years ago

It appears that you're starting a worker from within another worker, is that the case?

How many workers total are you spawning?

adrianpanicek commented 4 years ago

Issue can be solved by modifying Amp\Parallel\Context\Internal\ProcessHub::PROCESS_START_TIMEOUT. It would be cool to have this configurable instead of hardcoded.

EDIT: I'm using grumphp and it's spawning multiple xdebug instances. After increasing said constant the issue went away.

enumag commented 4 years ago

It appears that you're starting a worker from within another worker, is that the case?

No. Worker was started from the main loop process.

How many workers total are you spawning?

The error appeared with the first worker already.

enumag commented 4 years ago

Issue can be solved by modifying Amp\Parallel\Context\Internal\ProcessHub::PROCESS_START_TIMEOUT. It would be cool to have this configurable instead of hardcoded.

EDIT: I'm using grumphp and it's spawning multiple xdebug instances. After increasing said constant the issue went away.

How far did you increase it? I remember trying that as well to no avail.

adrianpanicek commented 4 years ago

@enumag I just added zero at the end.

enumag commented 4 years ago

Yeah, I tried even higher to no avail. It's simply not working for me with xdebug active.

sakuraza commented 4 years ago

Hi, I have this problem too. I have no xdebug install, and i try to increase PROCESS_START_TIMEOUT with no success. I just try to execute the code on this link https://amphp.org/parallel/ My environnement : centos 7 apache 2.4.6 php 7.2

the error :

<status>500</status> <error>Amp\Parallel\Context\ContextException</error> <message>Starting the process failed</message> <file>.../vendor/amphp/parallel/lib/Context/Process.php</file> <line>202</line>

<trace> 0 [internal function]: Amp\Parallel\Context\Process->Amp\Parallel\Context{closure}() 1 .../vendor/amphp/amp/lib/Coroutine.php(115): Generator->throw(Object(Amp\Parallel\Context\ContextException)) 2 .../vendor/amphp/amp/lib/Failure.php(33): Amp\Coroutine->Amp{closure}(Object(Amp\Parallel\Context\ContextException), NULL) 3 .../vendor/amphp/amp/lib/Internal/Placeholder.php(143): Amp\Failure->onResolve(Object(Closure)) 4 .../vendor/amphp/amp/lib/Internal/Placeholder.php(177): Amp\Coroutine->resolve(Object(Amp\Failure)) 5 .../vendor/amphp/amp/lib/Coroutine.php(137): Amp\Coroutine->fail(Object(Amp\Parallel\Context\ContextException)) 6 .../vendor/amphp/amp/lib/Failure.php(33): Amp\Coroutine->Amp{closure}(Object(Amp\TimeoutException), NULL) 7 .../vendor/amphp/amp/lib/Internal/Placeholder.php(143): Amp\Failure->onResolve(Object(Closure)) 8 .../vendor/amphp/amp/lib/Internal/Placeholder.php(177): class@anonymous->resolve(Object(Amp\Failure)) 9 .../vendor/amphp/amp/lib/Deferred.php(65): class@anonymous->fail(Object(Amp\TimeoutException)) 10 .../vendor/amphp/amp/lib/functions.php(275): Amp\Deferred->fail(Object(Amp\TimeoutException)) 11 .../vendor/amphp/amp/lib/Loop/NativeDriver.php(111): Amp\Promise{closure}('r', NULL) 12 .../vendor/amphp/amp/lib/Loop/Driver.php(138): Amp\Loop\NativeDriver->dispatch(true) 13 .../vendor/amphp/amp/lib/Loop/Driver.php(72): Amp\Loop\Driver->tick() 14 .../vendor/amphp/amp/lib/Loop.php(95): Amp\Loop\Driver->run() 15 .../vendor/amphp/amp/lib/functions.php(229): Amp\Loop::run(Object(Closure)) 16 .../Controller/Admin.php(65): Amp\Promise\wait(Object(Amp\Internal\PrivatePromise)) 17 [internal function]: Api\Controller\Admin->test() </trace>

Thank for your help

trowski commented 1 year ago

Closing this issue, since this has been completely refactored in v2 to allow full customization of context IPC.