简体   繁体   中英

How to STOP python to complete execution on one operation and then start other process

def fun1():
    #something(opens a command window in a folder and run something)
    os.system("start cmd /c omake clean ")
def fun2():
    #something(opens a command window again in the same folder and run something else)
    os.system("start cmd /c omake ")

for dir in list_of_dir:
    os.chdir(dir)
    fun1()
    fun2()

#The above structure is just an example, If you see in the for loop the fun1() and fun2() #calls happened simultaneously #But how can somebody first execute fun1() completely including the closure of command window #and then only move to calling fun2() in python.

#Kindly guide me on this..

#Thank you.

Please avoid running scripts that way. Also do not name variables like dir. It helps a lot to get an editor which does some linting

Just an example. Still it would be better to know what you try to achieve?

import os
from os import listdir
from os.path import isfile, join

def fun1():
    os.system("dir")
    print('fun1: done!')
    
    
def fun2():
    os.system("dir")
    print('fun1: done!')


path_folder = "c:/Windows"
file_names = [f for f in listdir(path_folder) if isfile(join(path_folder, f))]


for filen_name in file_names:
    os.chdir(path_folder)
    fun1()
    fun2()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM