def stop(self, timeout=None):
assert self.has_started(), "<STR_LIT>"<EOL>greenlet = self._greenlet if gevent.getcurrent() != self._greenlet else None<EOL>self._stop_event.set()<EOL>if greenlet is not None and timeout is not None:<EOL><INDENT>greenlet.join(timeout)<EOL>return greenlet.ready<EOL><DEDENT>else:<EOL><INDENT>return True<EOL><DEDENT>
Stops a running loop and waits for it to end if timeout is set. Calling a non-running loop is an error.
:param timeout: time (in seconds) to wait for the loop to end after signalling it. ``None`` is to block till it
ends.
:return: True if the loop stopped, False if still stopping.