Skip to content

Instantly share code, notes, and snippets.

@jacobtomlinson
Created November 2, 2023 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacobtomlinson/640fe8f071a35b5c375f81954c979547 to your computer and use it in GitHub Desktop.
Save jacobtomlinson/640fe8f071a35b5c375f81954c979547 to your computer and use it in GitHub Desktop.
Databrick run
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