| 585 | super().start_session(capabilities) |
| 586 | |
| 587 | def quit(self): |
| 588 | try: |
| 589 | logger.debug("Terminating the UC browser") |
| 590 | os.kill(self.browser_pid, 15) |
| 591 | self._already_quit = True |
| 592 | if "linux" in sys.platform: |
| 593 | os.waitpid(self.browser_pid, 0) |
| 594 | time.sleep(0.02) |
| 595 | else: |
| 596 | time.sleep(0.04) |
| 597 | except (AttributeError, ChildProcessError, RuntimeError, OSError): |
| 598 | time.sleep(0.05) |
| 599 | except TimeoutError as e: |
| 600 | logger.debug(e, exc_info=True) |
| 601 | except Exception: |
| 602 | pass |
| 603 | with suppress(Exception): |
| 604 | self.stop_client() |
| 605 | with suppress(Exception): |
| 606 | if hasattr(self, "command_executor") and self.command_executor: |
| 607 | self.command_executor.close() |
| 608 | |
| 609 | # Remove instance reference to allow garbage collection |
| 610 | Chrome._instances.discard(self) |
| 611 | |
| 612 | if hasattr(self, "service") and getattr(self.service, "process", None): |
| 613 | logger.debug("Stopping webdriver service") |
| 614 | with suppress(Exception): |
| 615 | try: |
| 616 | self.service.send_remote_shutdown_command() |
| 617 | except TypeError: |
| 618 | pass |
| 619 | finally: |
| 620 | with suppress(Exception): |
| 621 | self.service._terminate_process() |
| 622 | if ( |
| 623 | hasattr(self, "reactor") |
| 624 | and self.reactor |
| 625 | and hasattr(self.reactor, "event") |
| 626 | ): |
| 627 | logger.debug("Shutting down Reactor") |
| 628 | with suppress(Exception): |
| 629 | self.reactor.event.set() |
| 630 | self.reactor.join(timeout=2) |
| 631 | self.reactor = None |
| 632 | if ( |
| 633 | hasattr(self, "keep_user_data_dir") |
| 634 | and hasattr(self, "user_data_dir") |
| 635 | and not self.keep_user_data_dir |
| 636 | ): |
| 637 | import shutil |
| 638 | for _ in range(5): |
| 639 | try: |
| 640 | shutil.rmtree(self.user_data_dir, ignore_errors=False) |
| 641 | except FileNotFoundError: |
| 642 | pass |
| 643 | except (RuntimeError, OSError, PermissionError) as e: |
| 644 | logger.debug( |