python - 在 Python 中并行运行脚本
问题描述
我有一个一直在创建文件的文件夹,一旦文件大小达到 100 兆字节,就意味着它已准备好加载到数据库中。加载过程最终应该并行完成。同时五个文件。
在 Powershell 中,我通过调用并行命令轻松地做到了这一点。
我编写了一个脚本,打开与数据库的连接,运行程序并执行BULK INSERT
将文件上传到数据库的命令。
import pymssql
import os
try:
# Open DB Connection
conn = pymssql.connect(server=server, database=Database, timeout=60)
c1 = conn.cursor(as_dict=True)
#Run First procedure with the File Name Variable
c1.callproc("First.procedure", (FileName ,))
# Recieve Variables from the First Procedure
for row in c1:
NewFileId= row['FileId']
DestinationTableName= row['DestinationTableName']
conn.commit()
# Upload the CSV file to the DB
string = "BULK INSERT DestinationTableName FROM '{CSV FILE}' WITH( FIELDTERMINATOR = ',', DATAFILETYPE = 'CHAR');"
c1.execute(string)
conn.commit()
#Run the Second procedure with the File ID and Table Name Variables
c1.callproc("2nd.procedure", (FileId, DestinationTableName,))
conn.commit()
conn.close()
f.close()
except pymssql.Error as e:
File = open("Error.txt", "a")
File.write(repr(e))
我想通过一次发送五个文件名来并行运行脚本。通过 Python 实现的任何建议?
解决方案
推荐阅读
- dart - Flutter:构造函数中List参数的默认分配
- javascript - 如何使用 jsPdf 设置修剪框?
- android - Android Studio 说“ADB.exe 已过时并且存在严重的性能问题”,尽管 SDK 工具说一切都是最新的
- c - 如何避免重写不改变的文本片段
- javascript - 在存储操作中进行数据操作后同步提交 Vuex 突变
- database - 如何查找文档,哪个字段是特定字符串的子字符串?
- c# - DropdownList 值在 ASP.NET MVC 中为空
- python - Discord Bot 使用服务器授权(标头)
- c - 杀死分叉的子进程会杀死 SIGCHLD 处理程序中的父进程
- php - 如何将该代码放入可重用函数中?