asynchronous - running script multiple times simultaniously in python 2.7 -
hello trying run script multiple times take place @ same time understood use subprocess , threading when run it still looks being executed sequentially can me can run same script on , on @ same time? in fact working , slow?
edit forgot last piece of code @ bottom
here have far
import os import datetime import threading subprocess import popen today = datetime.date.today() os.makedirs("c:/newscript_image/" + str(today)) class mythread(threading.thread): def run(self): filename in os.listdir('./newscript/'): if '.htm' in filename: name = filename.strip('.htm') dbfolder = "c:/newscript/db/" + name os.makedirs(dbfolder) popen("python.exe c:/execution.py" + ' ' + filename + ' ' + name + ' ' + str(today) + ' ' + dbfolder) mythread().start()
personally, i'd use multiprocessing. i'd write function takes filename , whatever main guts of execution (probably importing execution , running function within it):
import multiprocessing import execution import datetime #assume have function: #exection.run_main_with_args(filename,name,today_str,dbfolder) today = datetime.datetime.today() def my_execute(filename): if '.htm' in filename: name = filename.strip('.htm') dbfolder = "c:/newscript/db/" + name os.makedirs(dbfolder) execution.run_main_with_args(filename,name,str(today),dbfolder) p = multiprocessing.pool() p.map(my_execute,list_of_files_to_process)
Comments
Post a Comment