From ee9f5fee1532ee88f43ae048b7ff18ffdda824a5 Mon Sep 17 00:00:00 2001 From: Andrew Pikul Date: Fri, 27 Sep 2024 15:26:41 -0400 Subject: [PATCH 01/26] Try running mac subprocess in thread w/o async --- devtools/browser.py | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/devtools/browser.py b/devtools/browser.py index 4065bfd4..ecce7110 100644 --- a/devtools/browser.py +++ b/devtools/browser.py @@ -182,17 +182,34 @@ async def _open_async(self): stderr = self._stderr env = self._env if platform.system() != "Windows": - self.subprocess = await asyncio.create_subprocess_exec( - sys.executable, - os.path.join( - os.path.dirname(os.path.realpath(__file__)), "chrome_wrapper.py" - ), - stdin=self.pipe.read_to_chromium, - stdout=self.pipe.write_from_chromium, - stderr=stderr, - close_fds=True, - env=env, - ) + if platform.system() == "Linux": + self.subprocess = await asyncio.create_subprocess_exec( + sys.executable, + os.path.join( + os.path.dirname(os.path.realpath(__file__)), "chrome_wrapper.py" + ), + stdin=self.pipe.read_to_chromium, + stdout=self.pipe.write_from_chromium, + stderr=stderr, + close_fds=True, + env=env, + ) + else: # mac doesn't seem to like asyncio.create_subprocess_exec + def run(): + return subprocess.Popen( + [ + sys.executable, + os.path.join( + os.path.dirname(os.path.realpath(__file__)), "chrome_wrapper.py" + ), + ], + close_fds=True, + stdin=self.pipe.read_to_chromium, + stdout=self.pipe.write_from_chromium, + stderr=stderr, + env=env, + ) + self.subprocess = await asyncio.to_thread(run) else: from .chrome_wrapper import open_browser self.subprocess = await open_browser(to_chromium=self.pipe.read_to_chromium, From 1a12ff51bb9c948155ee1999c369ec708a9491d3 Mon Sep 17 00:00:00 2001 From: Andrew Pikul Date: Fri, 27 Sep 2024 15:35:25 -0400 Subject: [PATCH 02/26] Improve DTDoctor --- devtools/browser.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/devtools/browser.py b/devtools/browser.py index ecce7110..4c80a1f5 100644 --- a/devtools/browser.py +++ b/devtools/browser.py @@ -592,27 +592,33 @@ def write_json(self, obj): return key def diagnose(): - print("*****************************************") - print("Please copy and paste all these results to an issue or to slack!") - print("Collecting information about the system:") + print("*".center(50, "*")) + print("Collecting information about the system:".center(50, "*")) print(platform.system()) print(platform.release()) print(platform.version()) print(platform.uname()) - print("Looking for browser:") + print("Looking for browser:".center(50, "*")) print(which_browser()) - print("Running a very simple test...") try: + print("Looking for version info:".center(50, "*")) import subprocess, sys # noqa print(subprocess.check_output([sys.executable, '-m', 'pip', 'freeze'])) print(subprocess.check_output(["git", "describe", "--all", "--tags", "--long", "--always",])) print(sys.version) print(sys.version_info) finally: + print("Done with version info.".center(50, "*")) pass async def test(): browser = await Browser(debug=True, debug_browser=True) await asyncio.sleep(2) await browser.close() - asyncio.run(test()) + try: + print("Running Asyncio Test".center(50, "*")) + asyncio.run(test()) + finally: + print("Asyncio.run done".center(50, "*")) + pass + print("") print("Thank you! Please share these results with us!") From 6768fff0df36a06ba0a3420b88bcef35e4798d94 Mon Sep 17 00:00:00 2001 From: Andrew Pikul Date: Fri, 27 Sep 2024 15:47:56 -0400 Subject: [PATCH 03/26] Add sync test to dtd and skip async test --- devtools/browser.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/devtools/browser.py b/devtools/browser.py index 4c80a1f5..258a6b1b 100644 --- a/devtools/browser.py +++ b/devtools/browser.py @@ -610,13 +610,23 @@ def diagnose(): finally: print("Done with version info.".center(50, "*")) pass + try: + print("Sync test".center(50, "*")) + import time + browser = Browser(debug=True, debug_browser=True) + time.sleep(2) + browser.close() + finally: + print("Done with sync test".center(50, "*")) + async def test(): browser = await Browser(debug=True, debug_browser=True) await asyncio.sleep(2) await browser.close() try: print("Running Asyncio Test".center(50, "*")) - asyncio.run(test()) + #asyncio.run(test()) + print("Skipped...") finally: print("Asyncio.run done".center(50, "*")) pass From 2a0b15a8d0dce1da9ce7ac805a55dd5b2e428b2d Mon Sep 17 00:00:00 2001 From: Andrew Pikul Date: Fri, 27 Sep 2024 15:49:38 -0400 Subject: [PATCH 04/26] Actually catch errors in try/except doh --- devtools/browser.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/devtools/browser.py b/devtools/browser.py index 258a6b1b..998e3a81 100644 --- a/devtools/browser.py +++ b/devtools/browser.py @@ -607,6 +607,8 @@ def diagnose(): print(subprocess.check_output(["git", "describe", "--all", "--tags", "--long", "--always",])) print(sys.version) print(sys.version_info) + except BaseException: + pass finally: print("Done with version info.".center(50, "*")) pass @@ -616,6 +618,8 @@ def diagnose(): browser = Browser(debug=True, debug_browser=True) time.sleep(2) browser.close() + except BaseException: + pass finally: print("Done with sync test".center(50, "*")) @@ -627,6 +631,8 @@ async def test(): print("Running Asyncio Test".center(50, "*")) #asyncio.run(test()) print("Skipped...") + except BaseException: + pass finally: print("Asyncio.run done".center(50, "*")) pass From 00eb56e2054d47df4f6b26492b9d23a18a91e90b Mon Sep 17 00:00:00 2001 From: Andrew Pikul Date: Fri, 27 Sep 2024 15:54:10 -0400 Subject: [PATCH 05/26] Collection exceptions for DTDoctor --- devtools/browser.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/devtools/browser.py b/devtools/browser.py index 998e3a81..1b3bbb11 100644 --- a/devtools/browser.py +++ b/devtools/browser.py @@ -592,6 +592,7 @@ def write_json(self, obj): return key def diagnose(): + fail = [] print("*".center(50, "*")) print("Collecting information about the system:".center(50, "*")) print(platform.system()) @@ -607,8 +608,8 @@ def diagnose(): print(subprocess.check_output(["git", "describe", "--all", "--tags", "--long", "--always",])) print(sys.version) print(sys.version_info) - except BaseException: - pass + except BaseException as e: + fail.append(e) finally: print("Done with version info.".center(50, "*")) pass @@ -619,7 +620,7 @@ def diagnose(): time.sleep(2) browser.close() except BaseException: - pass + fail.append(e) finally: print("Done with sync test".center(50, "*")) @@ -629,12 +630,16 @@ async def test(): await browser.close() try: print("Running Asyncio Test".center(50, "*")) - #asyncio.run(test()) - print("Skipped...") + asyncio.run(test()) except BaseException: - pass + fail.append(e) finally: print("Asyncio.run done".center(50, "*")) pass print("") + sys.stdout.flush() + sys.stderr.flush() + for exception in fail: + print(str(exception)) + if fail: raise BaseException("There was an exception, see above.") print("Thank you! Please share these results with us!") From 1f7fb095b6383ce2a51b2d204da7a0bd16f7d5d8 Mon Sep 17 00:00:00 2001 From: Andrew Pikul Date: Fri, 27 Sep 2024 15:55:10 -0400 Subject: [PATCH 06/26] Fix leftout vars --- devtools/browser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/devtools/browser.py b/devtools/browser.py index 1b3bbb11..fd670c85 100644 --- a/devtools/browser.py +++ b/devtools/browser.py @@ -619,7 +619,7 @@ def diagnose(): browser = Browser(debug=True, debug_browser=True) time.sleep(2) browser.close() - except BaseException: + except BaseException as e: fail.append(e) finally: print("Done with sync test".center(50, "*")) @@ -631,7 +631,7 @@ async def test(): try: print("Running Asyncio Test".center(50, "*")) asyncio.run(test()) - except BaseException: + except BaseException as e: fail.append(e) finally: print("Asyncio.run done".center(50, "*")) From 185b2fa6e7f4d05f148f930b329228cca0f5eaf6 Mon Sep 17 00:00:00 2001 From: Andrew Pikul Date: Fri, 27 Sep 2024 16:01:40 -0400 Subject: [PATCH 07/26] Try catching asyncio exception from inside task --- devtools/browser.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/devtools/browser.py b/devtools/browser.py index fd670c85..8280afde 100644 --- a/devtools/browser.py +++ b/devtools/browser.py @@ -625,9 +625,15 @@ def diagnose(): print("Done with sync test".center(50, "*")) async def test(): - browser = await Browser(debug=True, debug_browser=True) - await asyncio.sleep(2) - await browser.close() + try: + print("Internal running Asyncio Test".center(50, "*")) + browser = await Browser(debug=True, debug_browser=True) + await asyncio.sleep(2) + await browser.close() + except BaseException as e: + fail.append(e) + finally: + print("Asyncio.run done internally".center(50, "*")) try: print("Running Asyncio Test".center(50, "*")) asyncio.run(test()) @@ -635,7 +641,6 @@ async def test(): fail.append(e) finally: print("Asyncio.run done".center(50, "*")) - pass print("") sys.stdout.flush() sys.stderr.flush() From 3d37467a35945b43f9db86561d0bcde34a8c90b6 Mon Sep 17 00:00:00 2001 From: Andrew Pikul Date: Fri, 27 Sep 2024 16:11:22 -0400 Subject: [PATCH 08/26] Try catching asyncio exception w/ error handler --- devtools/browser.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/devtools/browser.py b/devtools/browser.py index 8280afde..75268fad 100644 --- a/devtools/browser.py +++ b/devtools/browser.py @@ -623,8 +623,10 @@ def diagnose(): fail.append(e) finally: print("Done with sync test".center(50, "*")) - + def error_handler(loop, context): + print(context) async def test(): + asyncio.get_running_loop().set_exception_handler(error_handler) try: print("Internal running Asyncio Test".center(50, "*")) browser = await Browser(debug=True, debug_browser=True) From b2108f766a1488c185b20d78794716ecc93617a1 Mon Sep 17 00:00:00 2001 From: Andrew Pikul Date: Fri, 27 Sep 2024 17:03:14 -0400 Subject: [PATCH 09/26] Skip async for now --- devtools/browser.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/devtools/browser.py b/devtools/browser.py index 75268fad..72450ab4 100644 --- a/devtools/browser.py +++ b/devtools/browser.py @@ -623,22 +623,14 @@ def diagnose(): fail.append(e) finally: print("Done with sync test".center(50, "*")) - def error_handler(loop, context): - print(context) async def test(): - asyncio.get_running_loop().set_exception_handler(error_handler) - try: - print("Internal running Asyncio Test".center(50, "*")) - browser = await Browser(debug=True, debug_browser=True) - await asyncio.sleep(2) - await browser.close() - except BaseException as e: - fail.append(e) - finally: - print("Asyncio.run done internally".center(50, "*")) + browser = await Browser(debug=True, debug_browser=True) + await asyncio.sleep(2) + await browser.close() try: print("Running Asyncio Test".center(50, "*")) - asyncio.run(test()) + #asyncio.run(test()) + print("skip") except BaseException as e: fail.append(e) finally: From 2d23ff12f537dc3d7ebd8ae94a7dc2b6c79b4ced Mon Sep 17 00:00:00 2001 From: Andrew Pikul Date: Fri, 27 Sep 2024 17:07:39 -0400 Subject: [PATCH 10/26] Use tracebook to get full exception --- devtools/browser.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/devtools/browser.py b/devtools/browser.py index 72450ab4..7c8bbac9 100644 --- a/devtools/browser.py +++ b/devtools/browser.py @@ -638,7 +638,9 @@ async def test(): print("") sys.stdout.flush() sys.stderr.flush() - for exception in fail: - print(str(exception)) - if fail: raise BaseException("There was an exception, see above.") + if fail: + import traceback + for exception in fail: + traceback.print_exception(exception) + raise BaseException("There was an exception, see above.") print("Thank you! Please share these results with us!") From 0cc101e04a8e91b72d5f04f3b733e0d3276efb9b Mon Sep 17 00:00:00 2001 From: Andrew Pikul Date: Fri, 27 Sep 2024 17:21:21 -0400 Subject: [PATCH 11/26] Cast path to str to help w/ mac fsencode --- devtools/browser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devtools/browser.py b/devtools/browser.py index 7c8bbac9..2b47561c 100644 --- a/devtools/browser.py +++ b/devtools/browser.py @@ -83,7 +83,7 @@ def __init__( if not path: path = default_path if path: - new_env["BROWSER_PATH"] = path + new_env["BROWSER_PATH"] = str(path) else: raise RuntimeError( "Could not find an acceptable browser. Please set environmental variable BROWSER_PATH or pass `path=/path/to/browser` into the Browser() constructor." From 47c8b9ebd94d4b8979c484afb5d72250516a441c Mon Sep 17 00:00:00 2001 From: Andrew Pikul Date: Fri, 27 Sep 2024 17:26:31 -0400 Subject: [PATCH 12/26] Remove unnecessary sol'n to_thread for mac Popen --- devtools/browser.py | 39 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/devtools/browser.py b/devtools/browser.py index 2b47561c..1ff64a3b 100644 --- a/devtools/browser.py +++ b/devtools/browser.py @@ -182,34 +182,17 @@ async def _open_async(self): stderr = self._stderr env = self._env if platform.system() != "Windows": - if platform.system() == "Linux": - self.subprocess = await asyncio.create_subprocess_exec( - sys.executable, - os.path.join( - os.path.dirname(os.path.realpath(__file__)), "chrome_wrapper.py" - ), - stdin=self.pipe.read_to_chromium, - stdout=self.pipe.write_from_chromium, - stderr=stderr, - close_fds=True, - env=env, - ) - else: # mac doesn't seem to like asyncio.create_subprocess_exec - def run(): - return subprocess.Popen( - [ - sys.executable, - os.path.join( - os.path.dirname(os.path.realpath(__file__)), "chrome_wrapper.py" - ), - ], - close_fds=True, - stdin=self.pipe.read_to_chromium, - stdout=self.pipe.write_from_chromium, - stderr=stderr, - env=env, - ) - self.subprocess = await asyncio.to_thread(run) + self.subprocess = await asyncio.create_subprocess_exec( + sys.executable, + os.path.join( + os.path.dirname(os.path.realpath(__file__)), "chrome_wrapper.py" + ), + stdin=self.pipe.read_to_chromium, + stdout=self.pipe.write_from_chromium, + stderr=stderr, + close_fds=True, + env=env, + ) else: from .chrome_wrapper import open_browser self.subprocess = await open_browser(to_chromium=self.pipe.read_to_chromium, From 26114837d8dbef4219b466da5ebb36d1fa01657d Mon Sep 17 00:00:00 2001 From: Andrew Pikul Date: Fri, 27 Sep 2024 17:38:46 -0400 Subject: [PATCH 13/26] Add debug to which_browser --- devtools/browser.py | 2 +- devtools/system.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/devtools/browser.py b/devtools/browser.py index 1ff64a3b..73589705 100644 --- a/devtools/browser.py +++ b/devtools/browser.py @@ -583,7 +583,7 @@ def diagnose(): print(platform.version()) print(platform.uname()) print("Looking for browser:".center(50, "*")) - print(which_browser()) + print(which_browser(debug=True)) try: print("Looking for version info:".center(50, "*")) import subprocess, sys # noqa diff --git a/devtools/system.py b/devtools/system.py index b782806c..bc875e62 100644 --- a/devtools/system.py +++ b/devtools/system.py @@ -2,7 +2,7 @@ import platform import os -chrome = ["chrome", "Chrome", "google-chrome", "google-chrome-stable", "chromium", "chromium-browser"] +chrome = ["chrome", "Chrome", "google-chrome", "google-chrome-stable", "Chrome.app", "Google Chrome", "chromium", "chromium-browser"] chromium = ["chromium", "chromium-browser"] # firefox = // this needs to be tested # brave = // this needs to be tested @@ -25,6 +25,7 @@ else: # assume mac, or system == "Darwin" default_path_chrome = [ "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" + "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome" ] def which_windows_chrome(): @@ -53,24 +54,28 @@ def _is_exe(path): finally: return res -def which_browser(executable_name=chrome): +def which_browser(executable_name=chrome, debug=False): path = None if isinstance(executable_name, str): executable_name = [executable_name] if platform.system() == "Windows": os.environ["NoDefaultCurrentDirectoryInExePath"] = "0" for exe in executable_name: + if debug: print(f"looking for {exe}", file=sys.stderr) if platform.system() == "Windows" and exe == "chrome": path = which_windows_chrome() if path and _is_exe(path): return path path = shutil.which(exe) + if debug: print(f"looking for {path}", file=sys.stderr) if path and _is_exe(path): return path default_path = [] if executable_name == chrome: default_path = default_path_chrome for candidate in default_path: + if debug: print(f"Looking at {candidate}", file=sys.stderr) if _is_exe(candidate): return default_path + if debug: print("Found nothing...") return None From 3f5db327f7cd246aee9512dad8833ce1428caa12 Mon Sep 17 00:00:00 2001 From: Andrew Pikul Date: Fri, 27 Sep 2024 17:44:25 -0400 Subject: [PATCH 14/26] Add missing import --- devtools/system.py | 1 + 1 file changed, 1 insertion(+) diff --git a/devtools/system.py b/devtools/system.py index bc875e62..8fb06b56 100644 --- a/devtools/system.py +++ b/devtools/system.py @@ -1,6 +1,7 @@ import shutil import platform import os +import sys chrome = ["chrome", "Chrome", "google-chrome", "google-chrome-stable", "Chrome.app", "Google Chrome", "chromium", "chromium-browser"] chromium = ["chromium", "chromium-browser"] From b641eda0408a45c1b2d311dc35b4c7ed56dcfa50 Mon Sep 17 00:00:00 2001 From: Andrew Pikul Date: Fri, 27 Sep 2024 17:48:36 -0400 Subject: [PATCH 15/26] Add missing comma :-( --- devtools/system.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/devtools/system.py b/devtools/system.py index 8fb06b56..2c035db6 100644 --- a/devtools/system.py +++ b/devtools/system.py @@ -25,8 +25,8 @@ ] else: # assume mac, or system == "Darwin" default_path_chrome = [ - "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" - "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome" + "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", + "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome", ] def which_windows_chrome(): From bf2b32b07b3db8fed13011cfd9b5e0ed4d66c2ad Mon Sep 17 00:00:00 2001 From: Andrew Pikul Date: Fri, 27 Sep 2024 17:52:04 -0400 Subject: [PATCH 16/26] Fix egregious variable swap --- devtools/system.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devtools/system.py b/devtools/system.py index 2c035db6..2efbd261 100644 --- a/devtools/system.py +++ b/devtools/system.py @@ -77,6 +77,6 @@ def which_browser(executable_name=chrome, debug=False): for candidate in default_path: if debug: print(f"Looking at {candidate}", file=sys.stderr) if _is_exe(candidate): - return default_path + return candidate if debug: print("Found nothing...") return None From 73beca7d886e9239845b3ff32d5816e40ee4707c Mon Sep 17 00:00:00 2001 From: Andrew Pikul Date: Fri, 27 Sep 2024 17:59:48 -0400 Subject: [PATCH 17/26] Unskip async test --- devtools/browser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devtools/browser.py b/devtools/browser.py index 73589705..578cf086 100644 --- a/devtools/browser.py +++ b/devtools/browser.py @@ -612,7 +612,7 @@ async def test(): await browser.close() try: print("Running Asyncio Test".center(50, "*")) - #asyncio.run(test()) + asyncio.run(test()) print("skip") except BaseException as e: fail.append(e) From d46ac6dd757f0526e1fab4c1b736350fa9bc9d3e Mon Sep 17 00:00:00 2001 From: Andrew Pikul Date: Fri, 27 Sep 2024 18:00:41 -0400 Subject: [PATCH 18/26] Add Google Chome.app to list of possible exes --- devtools/system.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devtools/system.py b/devtools/system.py index 2efbd261..731c8b33 100644 --- a/devtools/system.py +++ b/devtools/system.py @@ -3,7 +3,7 @@ import os import sys -chrome = ["chrome", "Chrome", "google-chrome", "google-chrome-stable", "Chrome.app", "Google Chrome", "chromium", "chromium-browser"] +chrome = ["chrome", "Chrome", "google-chrome", "google-chrome-stable", "Chrome.app", "Google Chrome", "Google Chrome.app", "chromium", "chromium-browser"] chromium = ["chromium", "chromium-browser"] # firefox = // this needs to be tested # brave = // this needs to be tested From 7fc9612bfb15b209cca9017a7b81abafc85dbac1 Mon Sep 17 00:00:00 2001 From: Andrew Pikul Date: Fri, 27 Sep 2024 18:07:51 -0400 Subject: [PATCH 19/26] Add some guards against unlikely None's --- devtools/browser.py | 4 ++-- devtools/pipe.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/devtools/browser.py b/devtools/browser.py index 578cf086..48c29baf 100644 --- a/devtools/browser.py +++ b/devtools/browser.py @@ -613,7 +613,6 @@ async def test(): try: print("Running Asyncio Test".center(50, "*")) asyncio.run(test()) - print("skip") except BaseException as e: fail.append(e) finally: @@ -624,6 +623,7 @@ async def test(): if fail: import traceback for exception in fail: - traceback.print_exception(exception) + if exception: + traceback.print_exception(exception) raise BaseException("There was an exception, see above.") print("Thank you! Please share these results with us!") diff --git a/devtools/pipe.py b/devtools/pipe.py index 34c19de2..be6e138c 100644 --- a/devtools/pipe.py +++ b/devtools/pipe.py @@ -59,6 +59,7 @@ def read_jsons(self, blocking=True, debug=None): except OSError as e: raise PipeClosedError() from e try: + raw_buffer = None # if we fail in read, we already defined raw_buffer = os.read( self.read_from_chromium, 10000 ) # 10MB buffer, nbd, doesn't matter w/ this From cf4c7466a593351a3d1db91c4580a2936cc9c3e7 Mon Sep 17 00:00:00 2001 From: Andrew Pikul Date: Fri, 27 Sep 2024 18:13:34 -0400 Subject: [PATCH 20/26] Check exists() not isfile() --- devtools/browser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devtools/browser.py b/devtools/browser.py index 48c29baf..27901393 100644 --- a/devtools/browser.py +++ b/devtools/browser.py @@ -242,7 +242,7 @@ def remove_readonly(func, path, excinfo): f"The temporary directory could not be deleted, execution will continue. {type(e)}: {e}", TempDirWarning ) if self.debug: - print(f"Tempfile still exists?: {bool(os.path.isfile(str(self.temp_dir.name)))}") + print(f"Tempfile still exists?: {bool(os.path.exists(str(self.temp_dir.name)))}") async def _is_closed_async(self, wait=0): waiter = self.subprocess.wait() From 981e8acad4cc84d1d9b442d2d89d089cf14926d6 Mon Sep 17 00:00:00 2001 From: Andrew Pikul Date: Fri, 27 Sep 2024 18:15:39 -0400 Subject: [PATCH 21/26] Make string regular string --- devtools/system.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devtools/system.py b/devtools/system.py index 731c8b33..e4aec946 100644 --- a/devtools/system.py +++ b/devtools/system.py @@ -26,7 +26,7 @@ else: # assume mac, or system == "Darwin" default_path_chrome = [ "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", - "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome", + r"/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome", ] def which_windows_chrome(): From 10238a876f6f6e39de0e1d502e10d69ededf91d0 Mon Sep 17 00:00:00 2001 From: Andrew Pikul Date: Fri, 27 Sep 2024 19:33:07 -0400 Subject: [PATCH 22/26] Look for bye in OSError, pipe: Also solves problem with temp files not getting deleted cause of crash --- devtools/pipe.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/devtools/pipe.py b/devtools/pipe.py index be6e138c..c50d8787 100644 --- a/devtools/pipe.py +++ b/devtools/pipe.py @@ -78,15 +78,21 @@ def read_jsons(self, blocking=True, debug=None): except OSError as e: if debug: print(f"caught OSError in read() {str(e)}", file=sys.stderr) - if not raw_buffer: + if not raw_buffer or raw_buffer == b'{bye}\n': raise PipeClosedError() # TODO this could be hard to test as it is a real OS corner case # but possibly raw_buffer is partial # and we don't check for partials decoded_buffer = raw_buffer.decode("utf-8") + if debug: + print(decoded_buffer, file=sys.stderr) for raw_message in decoded_buffer.split("\0"): if raw_message: - jsons.append(json.loads(raw_message)) + try: + jsons.append(json.loads(raw_message)) + except BaseException as e: + if debug: + print(f"Problem with {raw_message} in json: {e}", file=sys.stderr) if debug: # This debug is kinda late but the jsons package helps with decoding, since JSON optionally # allows escaping unicode characters, which chrome does (oof) From a1e7af0c1ff4c9fed8e5704366988181c5a83a35 Mon Sep 17 00:00:00 2001 From: Andrew Pikul Date: Mon, 30 Sep 2024 12:42:18 -0400 Subject: [PATCH 23/26] Remove escaped string in system.py: Wasn't necessary, Popen() communicates the arguments properly to mac w/o escaping the spaces. --- devtools/system.py | 1 - 1 file changed, 1 deletion(-) diff --git a/devtools/system.py b/devtools/system.py index e4aec946..f2c4bbb0 100644 --- a/devtools/system.py +++ b/devtools/system.py @@ -26,7 +26,6 @@ else: # assume mac, or system == "Darwin" default_path_chrome = [ "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", - r"/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome", ] def which_windows_chrome(): From 1790c386c0c55c4123833e0119e2f4a47e64ce19 Mon Sep 17 00:00:00 2001 From: Andrew Pikul Date: Tue, 1 Oct 2024 13:10:41 -0400 Subject: [PATCH 24/26] Add missing file=sys.stderr --- devtools/system.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devtools/system.py b/devtools/system.py index f2c4bbb0..33475b56 100644 --- a/devtools/system.py +++ b/devtools/system.py @@ -77,5 +77,5 @@ def which_browser(executable_name=chrome, debug=False): if debug: print(f"Looking at {candidate}", file=sys.stderr) if _is_exe(candidate): return candidate - if debug: print("Found nothing...") + if debug: print("Found nothing...", file=sys.stderr) return None From 6ecf20a044ebdda2a5fdaed534bdc0d80657366b Mon Sep 17 00:00:00 2001 From: Andrew Pikul Date: Tue, 1 Oct 2024 13:17:11 -0400 Subject: [PATCH 25/26] Store tempdir name out of unstable object --- devtools/browser.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/devtools/browser.py b/devtools/browser.py index 27901393..63d103fd 100644 --- a/devtools/browser.py +++ b/devtools/browser.py @@ -205,6 +205,7 @@ async def _open_async(self): self.future_self.set_result(self) def _clean_temp(self): + name = self.temp_dir.name clean = False try: self.temp_dir.cleanup() @@ -242,7 +243,7 @@ def remove_readonly(func, path, excinfo): f"The temporary directory could not be deleted, execution will continue. {type(e)}: {e}", TempDirWarning ) if self.debug: - print(f"Tempfile still exists?: {bool(os.path.exists(str(self.temp_dir.name)))}") + print(f"Tempfile still exists?: {bool(os.path.exists(str(self.name)))}") async def _is_closed_async(self, wait=0): waiter = self.subprocess.wait() From 91d18bc883162a81e356dcf53b45481fb52633fc Mon Sep 17 00:00:00 2001 From: Andrew Pikul Date: Tue, 1 Oct 2024 13:22:13 -0400 Subject: [PATCH 26/26] Finish last commit, missing change --- devtools/browser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devtools/browser.py b/devtools/browser.py index 63d103fd..4037d54a 100644 --- a/devtools/browser.py +++ b/devtools/browser.py @@ -243,7 +243,7 @@ def remove_readonly(func, path, excinfo): f"The temporary directory could not be deleted, execution will continue. {type(e)}: {e}", TempDirWarning ) if self.debug: - print(f"Tempfile still exists?: {bool(os.path.exists(str(self.name)))}") + print(f"Tempfile still exists?: {bool(os.path.exists(str(name)))}") async def _is_closed_async(self, wait=0): waiter = self.subprocess.wait()