Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
98 views
in Technique[技术] by (71.8m points)

python - Running command in parallel in pyspark

I have small snippet of code in pyspark.

# save data frame as temp table 
df.createOrReplaceTempView("my_table")

# save data frame as csv
df.write.format("csv").save("my_csv")

Now the 1st command executes then only 2nd will execute.

Is there a way where I can trigger both these commands in parallel i.e I want both commands to execute at the same time

question from:https://stackoverflow.com/questions/66054223/running-command-in-parallel-in-pyspark

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use python multiprocessing

from multiprocessing import Process

def create_temp_view(df):
    df.createOrReplaceTempView("my_table")

def write_df(df):
    df.write.mode("overwrite").format("csv").save("my_csv")


p1 = Process(create_temp_view(df))
p1.start()
p2 = Process(write_df(df))
p2.start()
p1.join()
p2.join()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...