日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux停止python程序_python – Linux上的多处理进程终止失败

發布時間:2024/4/11 linux 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux停止python程序_python – Linux上的多处理进程终止失败 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我剛剛注意到Linux上進程終止(來自多處理庫)方法的問題.我有應用程序使用多處理庫,但…當我在Windows上調用終止函數時,一切都很好,另一方面,Linux失敗了這個解決方案.作為過程殺戮的替代,我被迫使用

os.system('kill -9 {}'.format(pid))

我知道這不是太聰明,但它確實有效.所以我只是想知道為什么這段代碼在Windows上運行,但在Linux上運行失敗.

例:

from multiprocessing import Process

import os

process=Process(target=foo,args=('bar',))

pid=process.pid

process.terminate() # works on Windows only

...

os.sytem('kill -9 {}'.format(pid)) # my replacements on Linux

我的配置:python 3.2.0 build 88445; Linux的2.6.32-Debian的6.0.4

這是我的代碼中的示例.我希望這就足夠了.

def start_test(timestamp,current_test_suite,user_ip):

global_test_table[timestamp] = current_test_suite

setattr(global_test_table[timestamp],"user_ip",user_ip)

test_cases = global_test_table[timestamp].test_cases_table

test_cases = test_cases*int(global_test_table[timestamp].count + 1)

global_test_table[timestamp].test_cases_table = test_cases

print(test_cases)

print(global_test_table[timestamp].test_cases_table)

case_num = len(test_cases)

Report.basecounter = Report.casecounter = case_num

setattr(global_test_table[timestamp],"case_num",case_num)

setattr(global_test_table[timestamp],"user_current_test",0)

try:

dbobj=MySQLdb.connect(*dbconnector)

dbcursor=dbobj.cursor()

dbcursor.execute(sqlquery_insert_progress.format(progress_timestamp = str(timestamp),user_current_test = global_test_table[timestamp].user_current_tes$

except :...

for i in range(case_num):

user_row = global_test_table[timestamp]

current_test_from_tests_table = user_row.test_cases_table[i]

unittest.TextTestRunner(verbosity=2).run(suite(CommonGUI.get_address(CommonGUI,current_test_from_tests_table[1],current_test_from_tests_table[2],user$

global_test_table[timestamp].user_current_test = i + 1

try:

dbobj=MySQLdb.connect(*dbconnector)

dbcursor=dbobj.cursor()

dbcursor.execute(sqlquery_update_progress.format(progress_timestamp = str(timestamp),user_current_test = global_test_table[timestamp].user_current$

except :...

@cherrypy.expose()

def start_test_page(self,**test_suite):

timestamp = str(time.time())

user_ip = cherrypy.request.remote.ip

if on_server():

sys.stdout=sys.stderr=open("/var/log/cherrypy/test_gui/{file}.log".format(file=timestamp),"a")

current_test_suite = self.parse_result(**test_suite)

#global_test_table[timestamp] = current_test_suite

#setattr(global_test_table[timestamp],user_ip)

user_test_process = Process(target=start_test,args=(timestamp,user_ip))

users_process_table[timestamp] = user_test_process

user_test_process.start()

return '''{"testsuite_id" : "''' + str(timestamp) + '''"}'''

@cherrypy.expose()

def stop_test(self,timestamp):

if timestamp in users_process_table:

if on_server():

user_process_pid = users_process_table[timestamp].pid

os.system("kill -9 " + str(user_process_pid))

else:

users_process_table[timestamp].terminate()

del users_process_table[timestamp]

else:

return "No process exists"

總結

以上是生活随笔為你收集整理的linux停止python程序_python – Linux上的多处理进程终止失败的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。