Kills browser_process and processname_killed_atexit. Also removes the temporary Firefox profile that was created, if one exists.
()
| 348 | |
| 349 | |
| 350 | def kill_browser_process(): |
| 351 | """Kills browser_process and processname_killed_atexit. |
| 352 | |
| 353 | Also removes the temporary Firefox profile that was created, if one exists. |
| 354 | """ |
| 355 | global browser_process, processname_killed_atexit, current_browser_processes |
| 356 | if browser_process and browser_process.poll() is None: |
| 357 | try: |
| 358 | logv(f'Terminating browser process pid={browser_process.pid}..') |
| 359 | browser_process.kill() |
| 360 | except Exception as e: |
| 361 | logv(f'Failed with error {e}!') |
| 362 | |
| 363 | browser_process = None |
| 364 | # We have a hold of the target browser process explicitly, no need to resort to killall, |
| 365 | # so clear that record out. |
| 366 | processname_killed_atexit = '' |
| 367 | |
| 368 | if current_browser_processes: |
| 369 | for pid in current_browser_processes: |
| 370 | try: |
| 371 | logv(f'Terminating browser process pid={pid["pid"]}..') |
| 372 | os.kill(pid['pid'], 9) |
| 373 | except Exception as e: |
| 374 | logv(f'Failed with error {e}!') |
| 375 | |
| 376 | current_browser_processes = None |
| 377 | # We have a hold of the target browser process explicitly, no need to resort to killall, |
| 378 | # so clear that record out. |
| 379 | processname_killed_atexit = '' |
| 380 | |
| 381 | if processname_killed_atexit: |
| 382 | if emrun_options.android: |
| 383 | logv(f"Terminating Android app '{processname_killed_atexit}'.") |
| 384 | subprocess.call([ADB, 'shell', 'am', 'force-stop', processname_killed_atexit]) |
| 385 | else: |
| 386 | logv(f"Terminating all processes that have string '{processname_killed_atexit}' in their name.") |
| 387 | if WINDOWS: |
| 388 | process_image = processname_killed_atexit |
| 389 | if not process_image.endswith('.exe'): |
| 390 | process_image += '.exe' |
| 391 | subprocess.call(['taskkill', '/F', '/IM', process_image, '/T'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 392 | else: |
| 393 | try: |
| 394 | subprocess.call(['pkill', processname_killed_atexit]) |
| 395 | except OSError: |
| 396 | try: |
| 397 | subprocess.call(['killall', processname_killed_atexit]) |
| 398 | except OSError: |
| 399 | loge('Both commands pkill and killall failed to clean up the spawned browser process. Perhaps neither of these utilities is available on your system?') |
| 400 | delete_emrun_safe_firefox_profile() |
| 401 | # Clear the process name to represent that the browser is now dead. |
| 402 | processname_killed_atexit = '' |
| 403 | |
| 404 | delete_emrun_safe_firefox_profile() |
| 405 | |
| 406 | |
| 407 | # Heuristic that attempts to search for the browser process IDs that emrun spawned. |
no test coverage detected