简体   繁体   中英

How to trigger next package installation by “no command line activity” in Python

I build installation wizard to application in Python. Recognising all commands included - requires, prior to running - installing of about 20 different packages (project uses different calculation types, like: SVM, FFT, 3D harmonics, K-nearest neighbours, and additional packages for utilising command line and for GUI).

All packages - are needed to be installed one-after-another, sequentially (one installation finishes, then I want to start next package installation). During installation - there are different print status indications, which are automatically printed by installation (not me).

Eventually - all command line prints stop, and this "lack of activity of CMD" - I want to become trigger to run (by my project) next command for installation of next Python package. I think I may somehow use "stdout" emptiness, or other system entity. Please tell how to implement it, or provide short example, or link to example. Thanks in advance.

The default state of most things in programming is to wait for a function/method/process to return before moving on. For example, if you use subprocess.run() to run each command involved in installing, it will wait for the process to return before doing the next thing. The same goes for most other ways of installing.

In general, unless you explicitly use some form of concurrency (or something else that uses such, which will almost certainly say so in the documentation), it's going to wait.

So if your install commands are stored in variables cmd1 , cmd2 , etc, and none take any input once started:

# some code
subprocess.run(cmd1, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True)
subprocess.run(cmd2, stdout=subprocess.PIPE,  stderr=subprocess.PIPE, check=True)
# whatever follows that

will run cmd1 , then run cmd2 when cmd1 finishes, putting the stdout output of each to the existing stdout , and raising a CalledProcessError and stopping if either one returns non-zero.

Note that if you were to watch stdout instead, the result would probably break if anything was slow - a long blank period without actually being done.

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