<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def stop(self):
 """ Stops the GNS3 VM. """


        vm_state = yield from self._get_state()
        if vm_state == "poweroff":
            self.running = False
            return

        yield from self._execute("controlvm", [self._vmname, "acpipowerbutton"], timeout=3)
        trial = 120
        while True:
            try:
                vm_state = yield from self._get_state()
            # During a small amount of time the command will fail
            except GNS3VMError:
                vm_state = "running"
            if vm_state == "poweroff":
                break
            trial -= 1
            if trial == 0:
                yield from self._execute("controlvm", [self._vmname, "poweroff"], timeout=3)
                break
            yield from asyncio.sleep(1)

        log.info("GNS3 VM has been stopped")
        self.running = False