python - 用python调用多个过程

标签 python mysql linux

我有一个 linux 服务器,我想每天运行一个 python 脚本来运行 mysql 程序,但我不知道如何运行多个程序并设置一个条件,如果出现错误,它会向我发送一封电子邮件,其中包含错误的描述。这是我的脚本,只有一个过程:

#!/usr/bin/python

import MySQLdb

# Open database connection
db = MySQLdb.connect("localhost","user","password","bddname" )

# prepare a cursor object using cursor() method
cursor = db.cursor()

# execute SQL query using execute() method.
cursor.execute("CALL proc_commande_clts_detail7();")

# Fetch a single row using fetchone() method.
data = cursor.fetchone()
print "Database version : %s " % data

# disconnect from server
db.close()

感谢您的帮助。

最佳答案

您可以使用 callproc执行MySQL程序的方法

for proc_name in proc_name_list:
    try:
        result_args = cursor.callproc(proc_name, args=())
    except Exception as e:
        send_mail(str(e))

如果要调用多个过程,可以将 callproc 放在某种循环中,并使用 try...catch 进行错误处理。

关于python - 用python调用多个过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50051146/

相关文章:

python - numpy.sum 的内部结构

python - 将文件夹中的文件列为流以立即开始处理

python - 用 tensorflow 中的条件减少总和

mysql - 结合 JSON_SEARCH 和 JSON_EXTRACT 得到 : "Invalid JSON path expression."

mysql - 补丁后 MAMP 不适用于 Yosemite

php - 适用于 Android、PHP 和 MySQL 的 REST API

c++ - g++ 抛出 Skeleton wxwidget 项目 "undefined reference to main"错误

ruby - 安装作为 Ruby gem 实现的系统服务的方法

python - 如何使用pexpect自动输入ssh私钥密码

python - 检查列表是否包含另一个列表中的项目