Spaces:
Runtime error
Runtime error
akashyadav758 commited on
Commit ·
8cb8b03
1
Parent(s): dc356d0
Fix race condition in python navigation script
Browse files- start_hf.sh +15 -12
start_hf.sh
CHANGED
|
@@ -79,23 +79,26 @@ import socket
|
|
| 79 |
import urllib.parse
|
| 80 |
import time
|
| 81 |
|
| 82 |
-
# Wait for Chrome to start and expose
|
|
|
|
| 83 |
for _ in range(30):
|
| 84 |
try:
|
| 85 |
-
urllib.request.urlopen("http://127.0.0.1:9222/json")
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
except:
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
targets
|
| 93 |
-
page_target = [t for t in targets if t['type'] == 'page'][0]
|
| 94 |
-
ws_url = page_target['webSocketDebuggerUrl']
|
| 95 |
-
except Exception as e:
|
| 96 |
-
print("Failed to get targets:", e)
|
| 97 |
exit(1)
|
| 98 |
|
|
|
|
|
|
|
| 99 |
parsed = urllib.parse.urlparse(ws_url)
|
| 100 |
host = parsed.hostname
|
| 101 |
port = parsed.port or 9222
|
|
|
|
| 79 |
import urllib.parse
|
| 80 |
import time
|
| 81 |
|
| 82 |
+
# Wait for Chrome to start and expose a page target
|
| 83 |
+
page_target = None
|
| 84 |
for _ in range(30):
|
| 85 |
try:
|
| 86 |
+
res = urllib.request.urlopen("http://127.0.0.1:9222/json")
|
| 87 |
+
targets = json.loads(res.read().decode())
|
| 88 |
+
pages = [t for t in targets if t["type"] == "page"]
|
| 89 |
+
if pages:
|
| 90 |
+
page_target = pages[0]
|
| 91 |
+
break
|
| 92 |
except:
|
| 93 |
+
pass
|
| 94 |
+
time.sleep(1)
|
| 95 |
+
|
| 96 |
+
if not page_target:
|
| 97 |
+
print("Failed to get targets: No active page found")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
exit(1)
|
| 99 |
|
| 100 |
+
ws_url = page_target['webSocketDebuggerUrl']
|
| 101 |
+
|
| 102 |
parsed = urllib.parse.urlparse(ws_url)
|
| 103 |
host = parsed.hostname
|
| 104 |
port = parsed.port or 9222
|