python-3.x - 如何创建多个 Python 脚本并同时运行它们?
问题描述
我有一个 Python 脚本,用于在从各个方向暴露在风中时找到结构(起重机吊臂)上的一些应力。这意味着它会创建 360 个文本文件,结构所面临的每个度数对应 1 个。我不想在单个内核上运行 360 个连续循环,而是想将任务分解为 10 或 20 个进程。有没有办法我可以修改以下代码,以便它创建并运行具有不同度数范围的多个脚本,即一个脚本会做 0 到 20 度,接下来是 20 到 40 等等?
import math
import csv
boomDirection = 0
time = 0
maxStress = 650
with open("SomeWindAndHeadingStressMatrix.csv") as f:
data = [row for row in csv.reader(f)]
while boomDirection < 361:
file = open("SomeWindSpeedSourceData.txt", 'r')
data_file = open("Bolt Stress - " + str(boomDirection) + " Degrees.csv", 'w')
line = file.readline()
while line != '':
try:
if len(line.split(','))>1:
windSpeedHigh = int(int(line.split(',')[19])*1.32)
windSpeedLow = int(int(line.split(',')[22])*1.32)
windDirection = int(line.split(',')[14]) - boomDirection
if windDirection < 0:
windDirection += 360
stressHigh = float(data[windSpeedHigh][windDirection])
stressLow = float(data[windSpeedLow][windDirection])
if time % 10080 == 0:
data_file.write(str(time) + ', ' + str(maxStress) + ('\n'))
time += 0.5
else:
data_file.write(str(time) + ', ' + str(round(stressHigh,1)) + ('\n'))
time += 0.5
data_file.write(str(time) + ', ' + str(round(stressLow,1)) + ('\n'))
time += 0.5
except ValueError:
pass
line = file.readline()
data_file.close()
time = 0
boomDirection = boomDirection + 1
解决方案
推荐阅读
- python - Kivy 中小部件的位移
- php - 从捕获的组中提取值
- ios - 如何根据消息的长度更改 messageCell 的宽度?在迅速 4
- r - knitr::kable() 中的短标题
- java - 如何使用 FFMPEG 的 Java 包装库为 HLS 创建主播放列表
- python - Python3错误的导入路径
- python-2.7 - 使用 shell 启动进程,检测到可能的注入,安全问题
- php - Woocommerce 中我的帐户订单列表上的条件取消按钮
- c# - Arduino 使用 c# SerialPort.Write() 在标准固件上写入
- mysql - 选择所有没有 information_schema 的表