Skip to content

Instantly share code, notes, and snippets.

@lordlinus
Created May 9, 2022 03:57
Show Gist options
  • Save lordlinus/6fcfd4436d968d22e13f5722f54bd5d0 to your computer and use it in GitHub Desktop.
Save lordlinus/6fcfd4436d968d22e13f5722f54bd5d0 to your computer and use it in GitHub Desktop.
import time
from queue import Queue
from threading import Thread
table_list = [
"table1",
"table2",
"table3",
"table4",
"table5",
"table6",
"table7",
"table8",
"table9",
"table10",
]
q = Queue()
num_of_parallel_tasks = 4
for table in table_list:
q.put(table)
def load_table(table):
print(f"Loading {table}")
time.sleep(10)
# Write your spark code here
print(f"{table} loaded")
def run_tasks(function, q):
while not q.empty():
value = q.get()
function(value)
q.task_done()
for i in range(num_of_parallel_tasks):
t = Thread(target=run_tasks, args=(load_table, q))
t.daemon = True
t.start()
q.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment