Skip to content

Commit

Permalink
[skip ci] Fix browser process not being killed on POSIX systems
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-mil committed Sep 12, 2021
1 parent 2513fd5 commit 4ce77ec
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.0
1.3.1
23 changes: 19 additions & 4 deletions bing_rewards/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
from typing import Dict, Generator, List
from urllib.parse import quote_plus

if os.name == "posix":
import signal

import pyautogui

# Edge Browser user agents
Expand Down Expand Up @@ -214,9 +217,18 @@ def search(count, words_gen: Generator, agent, args, config):
# Open Chrome as a subprocess
# Only if a new window should be opened
if not args.no_window and not args.dryrun:
chrome = subprocess.Popen(
browser_cmd(args.exe or config.get("browser-path") or None, agent)
)
if os.name == "posix":
chrome = subprocess.Popen(
browser_cmd(args.exe or config.get("browser-path") or None, agent),
stderr=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
preexec_fn=os.setsid,
)
else:
chrome = subprocess.Popen(
browser_cmd(args.exe or config.get("browser-path") or None, agent),
)
print(chrome.pid)
except FileNotFoundError as e:
print("Unexpected error:", e)
print(
Expand Down Expand Up @@ -251,7 +263,10 @@ def search(count, words_gen: Generator, agent, args, config):

if not args.no_window and not args.dryrun:
# Close the Chrome window
chrome.terminate()
if os.name == "posix":
os.killpg(chrome.pid, signal.SIGTERM)
else:
chrome.kill()


def main():
Expand Down

0 comments on commit 4ce77ec

Please sign in to comment.