python - 同时发送消息python脚本

标签 python linux bash concurrency simultaneous

我为我们拥有的应用程序创建了 10 个用户帐户 我想让所有这 10 个用户同时发送消息。

所以我制作了 10 个 .py 脚本,在每个脚本中只有一个系统调用通过 `

"name of app cli client, some parameters including email and message"

到 bash,然后我使用 & 在一个命令中从 bash 运行所有这些 我的问题是我怎样才能做到这一点,但做得更好?

如何从 bash 中并行发送 10 条消息?不创建 10 个单独的 .py 脚本?任何帮助都会很好^^

最佳答案

import threading,os

ten_python_scripts = [] # mention all files here

def func(filename):
  x = subprocess.call("python {}".format(filename), shell=True)

threads = []
for filename in ten_python_scripts:
  x = threading.Thread(target=func, args=(filename,))
  threads.append(x)
for thread in threads:
  thread.start()
for thread in threads:
  thread.join()

关于python - 同时发送消息python脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52166160/

相关文章:

linux - shell 遍历自定义数字列表

python - 查找具有特定属性值的所有标签

python - strip 命令不会删除字符串中的 'e'

python - 具有 Python 属性的属性映射

linux - 使用交互式响应动态响应期望

c - Linux 用户空间程序的正确构建环境

bash - 在 shell 脚本中使用 read 命令逐行读取输入文件会跳过最后一行

python - 根据 DataFrame 中的值计数保留具有前 n 个项目的所有行

c++ - linux测时间问题! std::chrono、QueryPerformanceCounter、clock_gettime

bash - "source: command not found"通过 cmder 使用 git sh 运行脚本