Created
November 2, 2023 17:21
-
-
Save jacobtomlinson/640fe8f071a35b5c375f81954c979547 to your computer and use it in GitHub Desktop.
Databrick run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import subprocess | |
import time | |
import socket | |
DB_IS_DRIVER = os.getenv('DB_IS_DRIVER') | |
DB_DRIVER_IP = os.getenv('DB_DRIVER_IP') | |
if DB_IS_DRIVER == "TRUE": | |
print("This node is the Dask scheduler.") | |
subprocess.Popen(["dask", "scheduler"]) | |
else: | |
print("This node is a Dask worker.") | |
print(f"Connecting to Dask scheduler at {DB_DRIVER_IP}:8786") | |
while True: | |
try: | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
sock.connect((DB_DRIVER_IP, 8786)) | |
sock.close() | |
break | |
except ConnectionRefusedError: | |
print("Scheduler not available yet. Waiting...") | |
time.sleep(1) | |
subprocess.Popen(["dask", "worker", f"tcp://{DB_DRIVER_IP}:8786"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment