简体   繁体   English

如何停止 python 以完成一个操作的执行然后启动其他进程

[英]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. #上面的结构只是一个例子,如果你在for循环中看到fun1()和fun2() #calls同时发生#但是有人怎么能先完全执行fun1()包括关闭命令window #然后才移动在 python 中调用 fun2()。

#Kindly guide me on this.. #请在这方面指导我..

#Thank you. #谢谢。

Please avoid running scripts that way.请避免以这种方式运行脚本。 Also do not name variables like dir.也不要命名变量,如 dir。 It helps a lot to get an editor which does some linting获得一个做一些 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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python 3:我如何启动2个进程,从先完成的那个返回答案,并尽早停止另一个进程 - Python 3: How do i start 2 processes return the answer from whichever finishes first, and stop the other process early 如何在Python中停止一个进程 - how to stop one process from another in Python 如何确保一个进程在其他进程之前启动? - how to make sure one process start before other process? 出现异常/错误时如何不停止python中其他函数的执行 - How not to stop the execution of other function in python in case of Exception/Error 如何创建不确定的进度并在后台启动线程,然后在python中完成线程后再次执行一些操作 - How to create an indeterminate progress and start a thread in background and again do some operation after the thread is complete in python 如何在 Python 的循环内将一个进程的执行与另一个进程联系起来 - How to to tie the execution of one process to another inside a loop in Python 启动和停止进程的最佳 Python Web 框架 - Best python web framework to start and stop a process 当另一个函数在python上停止时如何停止一个函数 - how to stop one function when the other one stops on python 如何在 python 中启动一个线程池并在一个线程池完成时停止? - How to start a pool of threads and stop when one is finished in python? 如何在 Python 中开始新操作 - How to start new operation in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM