mirror of
https://github.com/danog/parallel.git
synced 2025-01-22 14:01:14 +01:00
Actually fix kill threads
This commit is contained in:
parent
b163207cea
commit
79f4adb26a
@ -68,6 +68,11 @@ class Fork implements ContextInterface
|
||||
$this->channel = null;
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
$this->kill(); // Will only terminate if the process is still running.
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the context is running.
|
||||
*
|
||||
|
@ -83,7 +83,7 @@ class Thread extends \Thread
|
||||
$coroutine = new Coroutine($this->execute($channel));
|
||||
$coroutine->done();
|
||||
|
||||
$timer = $loop->timer(self::KILL_CHECK_FREQUENCY, true, function () use ($loop, $coroutine, $channel) {
|
||||
$timer = $loop->timer(self::KILL_CHECK_FREQUENCY, true, function () use ($loop) {
|
||||
if ($this->killed) {
|
||||
$loop->stop();
|
||||
}
|
||||
@ -99,7 +99,7 @@ class Thread extends \Thread
|
||||
public function kill()
|
||||
{
|
||||
$this->killed = true;
|
||||
parent::kill();
|
||||
return parent::kill();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -138,13 +138,23 @@ class Thread implements ContextInterface
|
||||
*/
|
||||
public function kill()
|
||||
{
|
||||
if (null === $this->thread) {
|
||||
throw new StatusError('The thread has not been started.');
|
||||
}
|
||||
|
||||
if (null !== $this->thread) {
|
||||
$this->close();
|
||||
|
||||
$this->thread->kill();
|
||||
if ($this->thread->isRunning() && !$this->thread->kill()) {
|
||||
throw new ThreadException('Could not kill thread.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Kills the thread if it is still running.
|
||||
*
|
||||
* @throws \Icicle\Concurrent\Exception\ThreadException
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
$this->kill();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,7 +4,6 @@ namespace Icicle\Concurrent\Worker;
|
||||
use Icicle\Concurrent\ContextInterface;
|
||||
use Icicle\Concurrent\Exception\StatusError;
|
||||
use Icicle\Concurrent\Worker\Internal\TaskFailure;
|
||||
use Icicle\Coroutine\Coroutine;
|
||||
|
||||
class Worker implements WorkerInterface
|
||||
{
|
||||
@ -95,14 +94,4 @@ class Worker implements WorkerInterface
|
||||
{
|
||||
$this->context->kill();
|
||||
}
|
||||
|
||||
/**
|
||||
* Kills the worker when it is destroyed.
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if ($this->context->isRunning()) {
|
||||
$this->context->kill();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user