python、信号阻塞、数据库
我有一个关于信号以及运行 sql 命令时如何处理信号的问题。特别是,我有一个作为进程运行的 python 脚本,并且在其中创建了另一个进程。之后,运行数据库检查,并在该数据库检查内更改表列 NULLEGE 属性。我必须说这张桌子相当大......就像 GB 一样大,而且它会变得更大。 当我向主进程(运行数据库检查的进程)发送一个术语信号时,在该主进程内创建的第二个进程也应该终止。嗯……这种情况随时都会发生,除非数据库检查正在进行 NULLEGE 属性更改。完成此操作后,主进程终止,但不知何故信号处理程序被忽略(不进入处理信号的函数),因此没有 SIGTERM 被发送到主进程内创建的进程。这就是我被困在一个进程中的原因。
我的问题:是否有一种方法可以在运行数据库检查时阻止信号(如对它们进行排队),或者是否有另一种方法可以使用 python 将 TERM 信号发送到第二个进程?我已经成功地更改了 bash 脚本,该脚本将 python 脚本作为一个进程启动,以进行检查并在主进程终止后将 SIGTERM 发送到左侧进程...但我不希望以这种方式处理它。
或者有没有办法中断数据库检查?
ps:对于数据库处理,sqlalchemy 在 ubuntu linux 上的 python 2.6 下使用。
i have a question about signals and how they being handled when there is a sql command running. Particularly, i have a python script that runs as a process and inside it another process is being created. After that a data base check is being run and inside that database check a tables column NULLEGE attribute is being altered. i must say that table is fairly big ... as in GBs big and it gets bigger.
when i send send a term signal to the main process (the one that runs the database check) the second process that is created inside that main process should also terminate. well ... that happens at all times minus when the database check is doing that NULLEGE attribute alteration. when that is being done the main process terminates but somehow the signal handler is being ignored (doesn't enter the function handling the signal) and thus no SIGTERM is being sent to the process created inside the main one. and that is how i am being left with one stuck process.
My question: is there a way to block signals (as in queuing them) while the database check is being ran or is there another way of sending the TERM signal to the second process using python ? i have successfully altered the bash script that launches the python script as a process to do a check and send SIGTERM to the left process after the main process terminates ... but i would prefer not handling it this way.
or is there a way of interrupting the database check ?
ps: for database handling the sqlalchemy is being used under python 2.6 on ubuntu linux.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 MySQL 命令是 C 调用,它会阻止 Python 解释器。
最干净的方法可能是在发送 TERM 之前使用 mysql 或 mysql-python 中的“show processlist”和“kill”命令。
参见这里:
http://www.techrepublic.com /article/how-to-examine-and-kill-mysql-client-processes/5211762
Your MySQL command is a C-call, which blocks the Python interpreter.
The cleanest way is probably to use the "show processlist" and "kill" commands from mysql or mysql-python before you send TERM.
See here:
http://www.techrepublic.com/article/how-to-examine-and-kill-mysql-client-processes/5211762