Check if the browser is still running.
(self)
| 400 | ) |
| 401 | |
| 402 | def is_running(self): |
| 403 | """Check if the browser is still running.""" |
| 404 | if not getattr(self, "_process_pid", None): |
| 405 | return False |
| 406 | # Not good enough: return psutil.pid_exists(self._process_pid) |
| 407 | try: |
| 408 | process = psutil.Process(self._process_pid) |
| 409 | # Check for PID recycling: Is this actually our process? |
| 410 | if hasattr(self, "_process_create_time"): |
| 411 | if process.create_time() != self._process_create_time: |
| 412 | return False # The PID was reused by a different process! |
| 413 | # If the process is a zombie, assume the browser isn't running |
| 414 | return process.status() != psutil.STATUS_ZOMBIE |
| 415 | except psutil.NoSuchProcess: |
| 416 | return False |
| 417 | except Exception: |
| 418 | return None |
| 419 | |
| 420 | def remove_cdc_props_as_needed(self): |
| 421 | cdc_props = self._get_cdc_props() |