2016年6月2日 几乎是强迫自己在更新 关于python的多线程处理
来源:互联网 发布:网络投诉管理办法 编辑:程序博客网 时间:2024/05/17 00:19
老生常谈的东西
这是我这段代码的第21次更新了,依然不能实现全部的设计需求
然而都这个点儿了,先睡吧
欠下的债,早晚都要还的
try: import sys import time import os import platform import threading #os.chdir('../res') #sys.path.append(os.getcwd()) #from adb import ADB #except ImportError as e: # print("[f] Required module missing. %s" % e.args[0]) # sys.exit(-1)except: passclass StatusMonitor: def __init__(self): self.adb_task = None self._dict = {} try: base_dir = os.path.dirname(os.getcwd()) #Get the abs path for the config file configfile_path = os.path.join(base_dir, r'\untility\configfile.txt') #Get configfile.txt CONFIGFILE = open(configfile_path, 'r') adbstatus_path = os.path.join(base_dir, r'\logs\adb_status.txt') self.ADBFILE = open(adbstatus_path, 'a+') except: print ("File not exist") return False #Create a dict for the config file for line in CONFIGFILE: (key,value) = line.strip().split(':',maxsplit=1) self._dict[key] = value global adb_status_monitor self.adb_status_monitor = 1 def device_state_monitor_start(self): #status = self.multiprocessing.Value('b', 1) #print ("Sub process for ADB_status monitor started ",status) #adb_task = multiprocessing.Process(target=device_state_monitor_start) #adb_task.start() #Check adb status while True: if self.adb_status_monitor == 1: Time_mark = time.strftime("%Y-%m-%d %H:%M:%S") self.ADBFILE.write(str(Time_mark + ' ')) #adb_status = self._ABDInstance.shell_command('ping -c 5 localhost') adb_status = True if adb_status == True: self.ADBFILE.write('ADB works normally') self.ADBFILE.write('\n') print ('ADB works normally') #While ADB works normally, then check the Moneky process #monkey_result = self.shell_command( "\ps|grep com.android.commands.monkey\") monkey_result = True if monkey_result == True: self.ADBFILE.write('Monkey works normally') self.ADBFILE.write('\n') print ('Monkey works normally') else: self.ADBFILE.write('Monkey process is terminated') self.ADBFILE.write('\n') print ('Monkey works abnormally') else: self.ADBFILE.write('ADB is disconnected,and Monkey process can not be found') self.ADBFILE.write('\n') print ('ADB is disconnected') #wait 10 minutes time.sleep(8) else: break def device_state_monitor_stop(self): global adb_status_monitor self.adb_status_monitor = 0 self.ADBFILE.close() def regNewProcess(self): self.adb_task = threading.Thread(target=self.device_state_monitor_start) #self.adb_task.setDaemon(True) self.adb_task.start() print('The thread adb task start') #打印这句话证明线程启动 """def check_parameters(self): #Check the config file for blank value configfile = self._dict print (configfile) for key in configfile: if configfile[key] =='': print ([key], "Error: Value is blank") return False else: #print ([key,configfile[key]],'Pass') pass test_hour = self.get_parameters('TEST_HOUR') cycle_time = self.get_parameters('CYCLE_TIME') change_prof_hour = self.get_parameters('CHANGE_PROFILE_HOUR') test_type = self.get_parameters('TEST_TYPE') execute_method = self.get_parameters('EXECUTE_METHOD') #Check the Test_hour/Cycle_time/change_prof_hour if int(test_hour) < int(cycle_time): # 'TEST_HOUR' should longer than 'CYCLE_TIME' print ("Error: test_hour < cycle time is incorrect") return False elif int(cycle_time) < int(change_prof_hour): # 'CYCLE_TIME' should longer than 'CHANGE_PROFILE_TIME' print ("Error: cycle_time < change_prof_hour is incorrect") return False elif (test_type) != 'black'and (test_type) != 'white': # Only 'black' or 'white' is available in 'TEST_TYPE' print ("Error: test_type should be 'black' or 'white'.") return False elif (execute_method) != '1' and (execute_method) != '2': # Only '1' or '2' is available in 'EXECUTE_METHOD' print ("Error: execute_method should be '1' or '2'") return False else: print ("Check parameters completed.No error occurs") return True""" def get_parameters(self,item): value = self._dict.get(item,None) if value == None: print (item,' KEY error, please check the key_name') return value # Test module if __name__=='__main__': i = StatusMonitor() k = i.regNewProcess() #l = i.device_state_monitor_stop() mm = i.get_parameters('TEST_TYPE') print(k,mm)
0 0
- 2016年6月2日 几乎是强迫自己在更新 关于python的多线程处理
- 2005年4月6日--我一个文科生,开始准备转行做技术,在这里鼓励自己一下!我的终极目标是软件工程师!
- 自己实现多线程 2009年12月25日
- Java多线程的zip工具(2011年10月18日更新-提供源码下载)
- 写给2016年11月8日的自己
- 2016年3月16日,开始自己的博客
- 如何在自己的博客中加入时钟、天气、流量(更新修正)1月17日
- 关于CopyU!的常见问题解答[最后更新日期:2013年10月28日]
- 给新人的iOS面试资料(2016年3月6日更新)
- 2016年截止6月17日以来指引文档(Guide)的更新列表(Apple)
- 2010年10月10日,在CSDN开通自己的博客!
- 谷歌在中国还开放的服务列表更新-2010年3月21日
- 04年6月9日关于咨询的讨论
- 偷工减料制作自己的免杀木马 6月11日更新(秒杀主流11款杀软)
- 今天是2011年6月9日,是我的博客开通的日子... ...
- 关于jmp2013年10月6日
- 今天是2016年6月25日。我学前端已经整整两个月了
- 2016年11月6日 关于工作和人生的一些感悟
- 初识python 交叉排序
- HDU1698 线段树
- Mybatis 直接执行SQL
- Android5.0 v7 库中actionbar中既显示文字又显示图标
- 关键路径
- 2016年6月2日 几乎是强迫自己在更新 关于python的多线程处理
- [LeetCode]problem 80. Remove Duplicates from Sorted Array II
- Halting problem(停机问题)
- mysql距离函数st_distance
- TCP_CORK
- LightOJ 1045 I - Digits of Factorial
- UItableViewCell一些实用细节与技巧
- 构造函数与析构函数中不调用虚函数
- 阿里音乐-比赛记录(1)