Cannot manage in getting it working: Spatie\Async\Output\ParallelError
mmartinello opened this issue · comments
Hi,
I'm making a test to find out how this works but even with a very simple test I'm getting an Spatie\Async\Output\ParallelError
Exception:
IS SUPPORTED:
/Users/mm/Projects/async-test/test.php:14:
bool(true)
Spatie\Async\Output\ParallelError Object
(
[message:protected] =>
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /Users/mm/Projects/async-test/vendor/spatie/async/src/Output/ParallelError.php
[line:protected] => 11
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => /Users/mm/Projects/async-test/vendor/spatie/async/src/Process/ParallelProcess.php
[line] => 126
[function] => fromException
[class] => Spatie\Async\Output\ParallelError
[type] => ::
[args] => Array
(
[0] =>
)
)
[1] => Array
(
[file] => /Users/mm/Projects/async-test/vendor/spatie/async/src/Process/ProcessCallbacks.php
[line] => 54
[function] => resolveErrorOutput
[class] => Spatie\Async\Process\ParallelProcess
[type] => ->
[args] => Array
(
)
)
[2] => Array
(
[file] => /Users/mm/Projects/async-test/vendor/spatie/async/src/Pool.php
[line] => 232
[function] => triggerError
[class] => Spatie\Async\Process\ParallelProcess
[type] => ->
[args] => Array
(
)
)
[3] => Array
(
[file] => /Users/mm/Projects/async-test/vendor/spatie/async/src/Pool.php
[line] => 328
[function] => markAsFailed
[class] => Spatie\Async\Pool
[type] => ->
[args] => Array
(
[0] => Spatie\Async\Process\ParallelProcess Object
(
[process:protected] => Symfony\Component\Process\Process Object
(
[callback:Symfony\Component\Process\Process:private] =>
[hasCallback:Symfony\Component\Process\Process:private] =>
[commandline:Symfony\Component\Process\Process:private] => Array
(
[0] => /usr/local/Cellar/php/7.4.5_2/bin/php
[1] => /Users/mm/Projects/async-test/vendor/spatie/async/src/Runtime/ChildRuntime.php
[2] => /Users/mm/Projects/async-test/vendor/spatie/async/src/Runtime/../../../../autoload.php
[3] => QzozMjoiT3Bpc1xDbG9zdXJlXFNlcmlhbGl6YWJsZUNsb3N1cmUiOjM2Nzp7YTo1OntzOjM6InVzZSI7YToyOntzOjE6ImkiO2k6MDtzOjU6InRoaW5nIjtzOjM6ImZvbyI7fXM6ODoiZnVuY3Rpb24iO3M6MjA5OiJmdW5jdGlvbiAoKSB1c2UgKCRpLCAkdGhpbmcpIHsKICAgICAgICAkZmlsZV9wYXRoID0gIi9Vc2Vycy9tYXR0aWEvUHJvamVjdHMvaW5mb2p1aWNlLXBkZi1nZW5lcmF0b3IvJWQudHh0IjsKICAgICAgICAkZmlsZV9wYXRoID0gXHNwcmludGYoJGZpbGVfcGF0aCwgJGkpOwogICAgICAgIFxmaWxlX3B1dF9jb250ZW50cygkZmlsZV9wYXRoLCAkdGhpbmcpOwogICAgfSI7czo1OiJzY29wZSI7TjtzOjQ6InRoaXMiO047czo0OiJzZWxmIjtzOjMyOiIwMDAwMDAwMDNmOGJiY2FiMDAwMDAwMDA0OWU0NDY2NCI7fX0=
[4] =>
)
[cwd:Symfony\Component\Process\Process:private] => /Users/mm/Projects/async-test
[env:Symfony\Component\Process\Process:private] =>
[input:Symfony\Component\Process\Process:private] =>
[starttime:Symfony\Component\Process\Process:private] => 1635871015.4431
[lastOutputTime:Symfony\Component\Process\Process:private] => 1635871015.4431
[timeout:Symfony\Component\Process\Process:private] => 300
[idleTimeout:Symfony\Component\Process\Process:private] =>
[exitcode:Symfony\Component\Process\Process:private] => -1
[fallbackStatus:Symfony\Component\Process\Process:private] => Array
(
[signaled] => 1
[exitcode] => -1
[termsig] => 15
)
[processInformation:Symfony\Component\Process\Process:private] => Array
(
[command] => exec '/usr/local/Cellar/php/7.4.5_2/bin/php' '/Users/mm/Projects/async-test/vendor/spatie/async/src/Runtime/ChildRuntime.php' '/Users/mm/Projects/async-test/vendor/spatie/async/src/Runtime/../../../../autoload.php' 'QzozMjoiT3Bpc1xDbG9zdXJlXFNlcmlhbGl6YWJsZUNsb3N1cmUiOjM2Nzp7YTo1OntzOjM6InVzZSI7YToyOntzOjE6ImkiO2k6MDtzOjU6InRoaW5nIjtzOjM6ImZvbyI7fXM6ODoiZnVuY3Rpb24iO3M6MjA5OiJmdW5jdGlvbiAoKSB1c2UgKCRpLCAkdGhpbmcpIHsKICAgICAgICAkZmlsZV9wYXRoID0gIi9Vc2Vycy9tYXR0aWEvUHJvamVjdHMvaW5mb2p1aWNlLXBkZi1nZW5lcmF0b3IvJWQudHh0IjsKICAgICAgICAkZmlsZV9wYXRoID0gXHNwcmludGYoJGZpbGVfcGF0aCwgJGkpOwogICAgICAgIFxmaWxlX3B1dF9jb250ZW50cygkZmlsZV9wYXRoLCAkdGhpbmcpOwogICAgfSI7czo1OiJzY29wZSI7TjtzOjQ6InRoaXMiO047czo0OiJzZWxmIjtzOjMyOiIwMDAwMDAwMDNmOGJiY2FiMDAwMDAwMDA0OWU0NDY2NCI7fX0=' ""
[pid] => 40370
[running] =>
[signaled] =>
[stopped] =>
[exitcode] => -1
[termsig] => 0
[stopsig] => 0
)
[outputDisabled:Symfony\Component\Process\Process:private] =>
[stdout:Symfony\Component\Process\Process:private] => Resource id #46
[stderr:Symfony\Component\Process\Process:private] => Resource id #48
[process:Symfony\Component\Process\Process:private] => Resource id #57
[status:Symfony\Component\Process\Process:private] => terminated
[incrementalOutputOffset:Symfony\Component\Process\Process:private] => 0
[incrementalErrorOutputOffset:Symfony\Component\Process\Process:private] => 0
[tty:Symfony\Component\Process\Process:private] =>
[pty:Symfony\Component\Process\Process:private] =>
[options:Symfony\Component\Process\Process:private] => Array
(
[suppress_errors] => 1
[bypass_shell] => 1
)
[useFileHandles:Symfony\Component\Process\Process:private] =>
[processPipes:Symfony\Component\Process\Process:private] => Symfony\Component\Process\Pipes\UnixPipes Object
(
[ttyMode:Symfony\Component\Process\Pipes\UnixPipes:private] =>
[ptyMode:Symfony\Component\Process\Pipes\UnixPipes:private] =>
[haveReadSupport:Symfony\Component\Process\Pipes\UnixPipes:private] => 1
[pipes] => Array
(
)
[inputBuffer:Symfony\Component\Process\Pipes\AbstractPipes:private] =>
[input:Symfony\Component\Process\Pipes\AbstractPipes:private] =>
[blocked:Symfony\Component\Process\Pipes\AbstractPipes:private] =>
[lastError:Symfony\Component\Process\Pipes\AbstractPipes:private] =>
)
[latestSignal:Symfony\Component\Process\Process:private] => 15
)
[id:protected] => 140369
[pid:protected] => 40370
[output:protected] =>
[errorOutput:protected] =>
[startTime:protected] => 1635871015.4431
[successCallbacks:protected] => Array
(
[0] => Closure Object
(
[parameter] => Array
(
[$output] => <required>
)
)
)
[errorCallbacks:protected] => Array
(
[0] => Closure Object
(
[parameter] => Array
(
[$exception] => <required>
)
)
)
[timeoutCallbacks:protected] => Array
(
)
)
)
)
[4] => Array
(
[file] => /Users/mm/Projects/async-test/vendor/symfony/process/Process.php
[line] => 923
[function] => Spatie\Async\{closure}
[class] => Spatie\Async\Pool
[type] => ->
[args] => Array
(
[0] => 20
[1] => Array
(
[signo] => 20
[errno] => 0
[code] => 2
[status] => 15
[pid] => 40370
[uid] => 501
)
)
)
[5] => Array
(
[file] => /Users/mm/Projects/async-test/vendor/symfony/process/Process.php
[line] => 216
[function] => stop
[class] => Symfony\Component\Process\Process
[type] => ->
[args] => Array
(
[0] => 0
)
)
[6] => Array
(
[function] => __destruct
[class] => Symfony\Component\Process\Process
[type] => ->
[args] => Array
(
)
)
)
[previous:Exception:private] =>
)
ERROR: Spatie\Async\Output\ParallelError in /Users/mm/Projects/async-test/vendor/spatie/async/src/Output/ParallelError.php:11
Stack trace:
#0 /Users/mm/Projects/async-test/vendor/spatie/async/src/Process/ParallelProcess.php(126): Spatie\Async\Output\ParallelError::fromException('')
#1 /Users/mm/Projects/async-test/vendor/spatie/async/src/Process/ProcessCallbacks.php(54): Spatie\Async\Process\ParallelProcess->resolveErrorOutput()
#2 /Users/mm/Projects/async-test/vendor/spatie/async/src/Pool.php(232): Spatie\Async\Process\ParallelProcess->triggerError()
#3 /Users/mm/Projects/async-test/vendor/spatie/async/src/Pool.php(328): Spatie\Async\Pool->markAsFailed(Object(Spatie\Async\Process\ParallelProcess))
#4 /Users/mm/Projects/async-test/vendor/symfony/process/Process.php(923): Spatie\Async\Pool->Spatie\Async\{closure}(20, Array)
#5 /Users/mm/Projects/async-test/vendor/symfony/process/Process.php(216): Symfony\Component\Process\Process->stop(0)
#6 [internal function]: Symfony\Component\Process\Process->__destruct()
#7 {main}
Spatie\Async\Output\ParallelError Object
(
[message:protected] =>
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /Users/mm/Projects/async-test/vendor/spatie/async/src/Output/ParallelError.php
[line:protected] => 11
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => /Users/mm/Projects/async-test/vendor/spatie/async/src/Process/ParallelProcess.php
[line] => 126
[function] => fromException
[class] => Spatie\Async\Output\ParallelError
[type] => ::
[args] => Array
(
[0] =>
)
)
[1] => Array
(
[file] => /Users/mm/Projects/async-test/vendor/spatie/async/src/Process/ProcessCallbacks.php
[line] => 54
[function] => resolveErrorOutput
[class] => Spatie\Async\Process\ParallelProcess
[type] => ->
[args] => Array
(
)
)
[2] => Array
(
[file] => /Users/mm/Projects/async-test/vendor/spatie/async/src/Pool.php
[line] => 232
[function] => triggerError
[class] => Spatie\Async\Process\ParallelProcess
[type] => ->
[args] => Array
(
)
)
[3] => Array
(
[file] => /Users/mm/Projects/async-test/vendor/spatie/async/src/Pool.php
[line] => 328
[function] => markAsFailed
[class] => Spatie\Async\Pool
[type] => ->
[args] => Array
(
[0] => Spatie\Async\Process\ParallelProcess Object
(
[process:protected] => Symfony\Component\Process\Process Object
(
[callback:Symfony\Component\Process\Process:private] =>
[hasCallback:Symfony\Component\Process\Process:private] =>
[commandline:Symfony\Component\Process\Process:private] => Array
(
[0] => /usr/local/Cellar/php/7.4.5_2/bin/php
[1] => /Users/mm/Projects/async-test/vendor/spatie/async/src/Runtime/ChildRuntime.php
[2] => /Users/mm/Projects/async-test/vendor/spatie/async/src/Runtime/../../../../autoload.php
[3] => QzozMjoiT3Bpc1xDbG9zdXJlXFNlcmlhbGl6YWJsZUNsb3N1cmUiOjM2Nzp7YTo1OntzOjM6InVzZSI7YToyOntzOjE6ImkiO2k6MTtzOjU6InRoaW5nIjtzOjM6ImJhciI7fXM6ODoiZnVuY3Rpb24iO3M6MjA5OiJmdW5jdGlvbiAoKSB1c2UgKCRpLCAkdGhpbmcpIHsKICAgICAgICAkZmlsZV9wYXRoID0gIi9Vc2Vycy9tYXR0aWEvUHJvamVjdHMvaW5mb2p1aWNlLXBkZi1nZW5lcmF0b3IvJWQudHh0IjsKICAgICAgICAkZmlsZV9wYXRoID0gXHNwcmludGYoJGZpbGVfcGF0aCwgJGkpOwogICAgICAgIFxmaWxlX3B1dF9jb250ZW50cygkZmlsZV9wYXRoLCAkdGhpbmcpOwogICAgfSI7czo1OiJzY29wZSI7TjtzOjQ6InRoaXMiO047czo0OiJzZWxmIjtzOjMyOiIwMDAwMDAwMDNmOGJiY2E0MDAwMDAwMDA0OWU0NDY2NCI7fX0=
[4] =>
)
[cwd:Symfony\Component\Process\Process:private] => /Users/mm/Projects/async-test
[env:Symfony\Component\Process\Process:private] =>
[input:Symfony\Component\Process\Process:private] =>
[starttime:Symfony\Component\Process\Process:private] => 1635871015.4455
[lastOutputTime:Symfony\Component\Process\Process:private] => 1635871015.4455
[timeout:Symfony\Component\Process\Process:private] => 300
[idleTimeout:Symfony\Component\Process\Process:private] =>
[exitcode:Symfony\Component\Process\Process:private] => -1
[fallbackStatus:Symfony\Component\Process\Process:private] => Array
(
[signaled] => 1
[exitcode] => -1
[termsig] => 15
)
[processInformation:Symfony\Component\Process\Process:private] => Array
(
[command] => exec '/usr/local/Cellar/php/7.4.5_2/bin/php' '/Users/mm/Projects/async-test/vendor/spatie/async/src/Runtime/ChildRuntime.php' '/Users/mm/Projects/async-test/vendor/spatie/async/src/Runtime/../../../../autoload.php' 'QzozMjoiT3Bpc1xDbG9zdXJlXFNlcmlhbGl6YWJsZUNsb3N1cmUiOjM2Nzp7YTo1OntzOjM6InVzZSI7YToyOntzOjE6ImkiO2k6MTtzOjU6InRoaW5nIjtzOjM6ImJhciI7fXM6ODoiZnVuY3Rpb24iO3M6MjA5OiJmdW5jdGlvbiAoKSB1c2UgKCRpLCAkdGhpbmcpIHsKICAgICAgICAkZmlsZV9wYXRoID0gIi9Vc2Vycy9tYXR0aWEvUHJvamVjdHMvaW5mb2p1aWNlLXBkZi1nZW5lcmF0b3IvJWQudHh0IjsKICAgICAgICAkZmlsZV9wYXRoID0gXHNwcmludGYoJGZpbGVfcGF0aCwgJGkpOwogICAgICAgIFxmaWxlX3B1dF9jb250ZW50cygkZmlsZV9wYXRoLCAkdGhpbmcpOwogICAgfSI7czo1OiJzY29wZSI7TjtzOjQ6InRoaXMiO047czo0OiJzZWxmIjtzOjMyOiIwMDAwMDAwMDNmOGJiY2E0MDAwMDAwMDA0OWU0NDY2NCI7fX0=' ""
[pid] => 40371
[running] =>
[signaled] =>
[stopped] =>
[exitcode] => -1
[termsig] => 0
[stopsig] => 0
)
[outputDisabled:Symfony\Component\Process\Process:private] =>
[stdout:Symfony\Component\Process\Process:private] => Resource id #58
[stderr:Symfony\Component\Process\Process:private] => Resource id #60
[process:Symfony\Component\Process\Process:private] => Resource id #65
[status:Symfony\Component\Process\Process:private] => terminated
[incrementalOutputOffset:Symfony\Component\Process\Process:private] => 0
[incrementalErrorOutputOffset:Symfony\Component\Process\Process:private] => 0
[tty:Symfony\Component\Process\Process:private] =>
[pty:Symfony\Component\Process\Process:private] =>
[options:Symfony\Component\Process\Process:private] => Array
(
[suppress_errors] => 1
[bypass_shell] => 1
)
[useFileHandles:Symfony\Component\Process\Process:private] =>
[processPipes:Symfony\Component\Process\Process:private] => Symfony\Component\Process\Pipes\UnixPipes Object
(
[ttyMode:Symfony\Component\Process\Pipes\UnixPipes:private] =>
[ptyMode:Symfony\Component\Process\Pipes\UnixPipes:private] =>
[haveReadSupport:Symfony\Component\Process\Pipes\UnixPipes:private] => 1
[pipes] => Array
(
)
[inputBuffer:Symfony\Component\Process\Pipes\AbstractPipes:private] =>
[input:Symfony\Component\Process\Pipes\AbstractPipes:private] =>
[blocked:Symfony\Component\Process\Pipes\AbstractPipes:private] =>
[lastError:Symfony\Component\Process\Pipes\AbstractPipes:private] =>
)
[latestSignal:Symfony\Component\Process\Process:private] => 15
)
[id:protected] => 240369
[pid:protected] => 40371
[output:protected] =>
[errorOutput:protected] =>
[startTime:protected] => 1635871015.4455
[successCallbacks:protected] => Array
(
[0] => Closure Object
(
[parameter] => Array
(
[$output] => <required>
)
)
)
[errorCallbacks:protected] => Array
(
[0] => Closure Object
(
[parameter] => Array
(
[$exception] => <required>
)
)
)
[timeoutCallbacks:protected] => Array
(
)
)
)
)
[4] => Array
(
[file] => /Users/mm/Projects/async-test/vendor/symfony/process/Process.php
[line] => 923
[function] => Spatie\Async\{closure}
[class] => Spatie\Async\Pool
[type] => ->
[args] => Array
(
[0] => 20
[1] => Array
(
[signo] => 20
[errno] => 0
[code] => 2
[status] => 15
[pid] => 40371
[uid] => 501
)
)
)
[5] => Array
(
[file] => /Users/mm/Projects/async-test/vendor/symfony/process/Process.php
[line] => 216
[function] => stop
[class] => Symfony\Component\Process\Process
[type] => ->
[args] => Array
(
[0] => 0
)
)
[6] => Array
(
[function] => __destruct
[class] => Symfony\Component\Process\Process
[type] => ->
[args] => Array
(
)
)
)
[previous:Exception:private] =>
)
ERROR: Spatie\Async\Output\ParallelError in /Users/mm/Projects/async-test/vendor/spatie/async/src/Output/ParallelError.php:11
Stack trace:
#0 /Users/mm/Projects/async-test/vendor/spatie/async/src/Process/ParallelProcess.php(126): Spatie\Async\Output\ParallelError::fromException('')
#1 /Users/mm/Projects/async-test/vendor/spatie/async/src/Process/ProcessCallbacks.php(54): Spatie\Async\Process\ParallelProcess->resolveErrorOutput()
#2 /Users/mm/Projects/async-test/vendor/spatie/async/src/Pool.php(232): Spatie\Async\Process\ParallelProcess->triggerError()
#3 /Users/mm/Projects/async-test/vendor/spatie/async/src/Pool.php(328): Spatie\Async\Pool->markAsFailed(Object(Spatie\Async\Process\ParallelProcess))
#4 /Users/mm/Projects/async-test/vendor/symfony/process/Process.php(923): Spatie\Async\Pool->Spatie\Async\{closure}(20, Array)
#5 /Users/mm/Projects/async-test/vendor/symfony/process/Process.php(216): Symfony\Component\Process\Process->stop(0)
#6 [internal function]: Symfony\Component\Process\Process->__destruct()
#7 {main}
This is the code I'm trying to execute:
<?php
// Composer autoload
require_once(sprintf("%s/vendor/autoload.php", __DIR__));
use Spatie\Async\Pool;
// Check is supported
$is_supported = Pool::isSupported();
echo "IS SUPPORTED:\n";
var_dump($is_supported);
// Create a new pool
$pool = Pool::create();
$things = [];
$things[] = "foo";
$things[] = "bar";
foreach ($things as $i => $thing) {
$pool->add(function () use ($i, $thing) {
$file_path = "/Users/mattia/Projects/infojuice-pdf-generator/%d.txt";
$file_path = sprintf($file_path, $i);
file_put_contents($file_path, $thing);
})->then(function ($output) {
echo "SUCCESS";
})->catch(function (Throwable $exception) {
print_r($exception);
$msg = "ERROR: %s";
$msg = sprintf($msg, $exception);
echo sprintf("%s\n", $msg);
});
}
As you can see in the output, Pool::isSupported()
is true
.
I'm on Mac OS X 11.5.2 (Big Sur) with PHP 7.4.5:
~ > php --version
PHP 7.4.5 (cli) (built: Apr 23 2020 02:25:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Xdebug v2.9.5, Copyright (c) 2002-2020, by Derick Rethans
with Zend OPcache v7.4.5, Copyright (c), by Zend Technologies
Could you help me to find out where I'm wrong, please?
Thank you very much
I got an similar error and only could fix avoiding using "$pool->add()" and "$pool->wait()"...
Try this:
// Create a new pool
$pool = Pool::create();
$things = [];
$things[] = "foo";
$things[] = "bar";
foreach ($things as $i => $thing) {
$pool[] = async(function () use ($i, $thing) {
$file_path = "/Users/mattia/Projects/infojuice-pdf-generator/%d.txt";
$file_path = sprintf($file_path, $i);
file_put_contents($file_path, $thing);
})->then(function ($output) {
echo "SUCCESS";
})->catch(function (Throwable $exception) {
print_r($exception);
$msg = "ERROR: %s";
$msg = sprintf($msg, $exception);
echo sprintf("%s\n", $msg);
});
}
await($pool);
I'm running php 8.0.x
Dear contributor,
because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.
This issue is still unresolved
I have the same issue. I can't event run very simple tasks.
TestTaskOne.php
use Spatie\Async\Task;
class TestTaskOne extends Task
{
public function configure()
{
// TODO: Implement configure() method.
}
public function run()
{
\Yii::$app->cache->redis->set('task one', 'done');
}
}
TestTaskTwo.php
use Spatie\Async\Task;
class TestTaskTwo extends Task
{
public function configure()
{
// TODO: Implement configure() method.
}
public function run()
{
\Yii::$app->cache->redis->set('task two', 'done');
}
}
I keep getting ParallelError exception.
After digging into code, I have to import the vendor/autoload.php
file using this method:
$pool->autoload('/path/to/vendor/autoload.php');
It should do the magic.
For me it was running without specifying the binary (am running in a docker container). By default, it was using the php-fpm as the binary, which seems not to exists / work. So when creating the pull, specify the PATH of php which you can get by running whereis php
form within the docker container:
$pool = Pool::create()->withBinary('/usr/local/bin/php');