[Small story] Synchronize with Python without multithreading (limited use)

It's a very limited-use small story, but I'll try to synchronize without using multithreading, which I'm not sure about. Maybe it doesn't help most people. Also, there must be a better way. But this is enough. (At this point) I'm new to Python w

Thing you want to do

Actually, I wanted to do something like the following.

  1. Execute external command A
  2. Execute external command B
  3. Execute external command C when A and B are finished

External process execution

This could use subprocess. I used popen () because I don't want to wait until the end.

import subprocess

p1 = subprocess.popen("command_A")
p2 = subprocess.popen("command_B")

wait

To wait for both to finish. .. .. There was a wait ().

r1 = p1.wait()
r2 = p2.wait()

You can also check the return value properly.

External process execution

If there is no problem, execute the last external process. You don't have to synchronize this time, so check_call () etc. is OK.

p3 = subprocess.check_call("command_C")

Summary

Study more and write better code! (LOL)

Recommended Posts

[Small story] Synchronize with Python without multithreading (limited use)
[Small story] Get timestamp with Python
[Small story] Test image generation with Python / OpenCV
[Python] Use JSON with Python
Use mecab with Python3
python small story collection
Use DynamoDB with Python
Use Python 3.8 with Anaconda
Use python with docker
Use Trello API with python
Use Twitter API with Python
Use TUN / TAP with Python
Stumble story with Python array
Use subsonic API with python3
[Small story] [Python] Replace strings in 2D arrays with numbers
Python: How to use async with
Use PointGrey camera with Python (PyCapture2)
Use vl53l0x with Raspberry Pi (python)
Challenge LOTO 6 with Python without discipline
Print with python3 without line breaks
[Python] Use Basic/Digest authentication with Flask
Use NAIF SPICE TOOLKIT with Python
Use rospy with virtualenv in Python3
Use Python in pyenv with NeoVim
How to use FTP with Python
Use Windows 10 speech synthesis with Python
Use OpenCV with Python 3 in Window
Use PostgreSQL with Lambda (Python + psycopg2)
Use smbus with python3 under pyenv environment
Use DeepL with python (for dissertation translation)
Use Amazon Simple Notification Service with Python
[Python] Use string data with scikit-learn SVM
[Introduction to Python] Let's use foreach with Python
Use PIL and Pillow with Cygwin Python
Use cryptography library cryptography with Docker Python image
Use without installing python 2.x on Windows
Use Application Insights with Python 3 (including bottles)
Use C ++ functions from python with pybind11
Use selenium phantomjs webdriver with python unittest
Until you can use opencv with python
Use Python and MeCab with Azure Functions
I want to use MATLAB feval with python
Use additional Python packages with Serverless Framework (v1.x)
[Python3] A story stuck with time zone conversion
[Final story] Beginners tried Numeron AI with python
Specify the Python executable to use with virtualenv
Use logger with Python for the time being
Python> Run with run-time arguments> Use import argparse
Use multiple versions of python environment with pyenv
Wrap C with Cython for use from Python
A story stuck with handling Python binary data
The easiest way to use OpenCV with python
Story of trying to use tensorboard with pytorch
Use various rabbimq features with pika in python
I want to use Temporary Directory with Python2
How to use tkinter with python in pyenv
Use Python in Anaconda environment with VS Code
Use Welch's t-test (should) with or without homoscedasticity
Use Python and word2vec (learned) with Azure Databricks
Until you use PhantomJS with Python on Heroku
Wrap C ++ with Cython for use from Python