public function exec($timeout = null)
    {
        try {
            $this->start();
            $this->wait($timeout, 500);
            if ($this->isRunning()) {
                throw new Timeout;
            }
        } finally {
            $this->close();
        }
    }