@@ -441,7 +441,13 @@ def reconnect(self, timeout=0.1):
441441 with suppress (Exception ):
442442 if self .service .is_connectable ():
443443 self .stop_client ()
444- self .service .stop ()
444+ try :
445+ self .service .send_remote_shutdown_command ()
446+ except TypeError :
447+ pass
448+ finally :
449+ with suppress (Exception ):
450+ self .service ._terminate_process ()
445451 if isinstance (timeout , str ):
446452 if timeout .lower () == "breakpoint" :
447453 breakpoint () # To continue:
@@ -466,7 +472,13 @@ def reconnect(self, timeout=0.1):
466472 self .close ()
467473 if self .service .is_connectable ():
468474 self .stop_client ()
469- self .service .stop ()
475+ try :
476+ self .service .send_remote_shutdown_command ()
477+ except TypeError :
478+ pass
479+ finally :
480+ with suppress (Exception ):
481+ self .service ._terminate_process ()
470482 self .service .start ()
471483 self .start_session ()
472484 time .sleep (0.003 )
@@ -482,7 +494,13 @@ def disconnect(self):
482494 if self .service .is_connectable ():
483495 self .stop_client ()
484496 time .sleep (0.003 )
485- self .service .stop ()
497+ try :
498+ self .service .send_remote_shutdown_command ()
499+ except TypeError :
500+ pass
501+ finally :
502+ with suppress (Exception ):
503+ self .service ._terminate_process ()
486504 self ._is_connected = False
487505
488506 def connect (self ):
@@ -507,7 +525,13 @@ def connect(self):
507525 self .close ()
508526 if self .service .is_connectable ():
509527 self .stop_client ()
510- self .service .stop ()
528+ try :
529+ self .service .send_remote_shutdown_command ()
530+ except TypeError :
531+ pass
532+ finally :
533+ with suppress (Exception ):
534+ self .service ._terminate_process ()
511535 self .service .start ()
512536 self .start_session ()
513537 time .sleep (0.003 )
@@ -539,7 +563,13 @@ def quit(self):
539563 logger .debug ("Stopping webdriver service" )
540564 with suppress (Exception ):
541565 self .stop_client ()
542- self .service .stop ()
566+ try :
567+ self .service .send_remote_shutdown_command ()
568+ except TypeError :
569+ pass
570+ finally :
571+ with suppress (Exception ):
572+ self .service ._terminate_process ()
543573 with suppress (Exception ):
544574 if self .reactor and isinstance (self .reactor , Reactor ):
545575 logger .debug ("Shutting down Reactor" )
0 commit comments