创建子流程调用的顺序

问题描述 投票:0回答:1

我正在通过子过程函数调用5个脚本,但是我想确保它以与脚本中相同的顺序处理它,以确保依赖关系。有没有一种快速的方法来按顺序组合这5个子流程函数?

# CONNECT DATABASE
import seaborn as sns
import pandas as pd
from platform import python_version
import sys
import os
import subprocess
from sqlalchemy import create_engine
import sqlite3
# connection to database
db = sqlite3.connect('gencodb.db')
# cursor
cursor = db.cursor()

# ENTER THE DATA WEEKS
run_date = '29/02/2020'
this_wk = '29FEB20'
last_wk = '22FEB20'
prev_wk = '15FEB20'

subprocess.call("python 01_DataCleaning_Transactions.py".split() +
                [run_date, this_wk, last_wk, prev_wk], shell=True)

subprocess.call("python 02_DataCleaning_Views.py".split() +
                [run_date, this_wk, last_wk, prev_wk], shell=True)

subprocess.call("python 03_DataCleaning_SP.py".split() +
                [run_date, this_wk, last_wk, prev_wk], shell=True)

subprocess.call("python 04_DataCleaning_Inventory.py".split() +
                [run_date, this_wk, last_wk, prev_wk], shell=True)

subprocess.call("python 05_DataCleaning_QAs.py".split() +
                [run_date, this_wk, last_wk, prev_wk], shell=True)
python subprocess
1个回答
0
投票

代替使用subprocess.call,应使用subprocess.run函数,它等待过程完成并返回CompletedProcess

注意:

subprocess.run(args)

运行args描述的命令。等待命令完成,然后返回CompletedProcess实例。

您可以在Python docs处引用更多信息>

© www.soinside.com 2019 - 2024. All rights reserved.