Using Python and multiprocessing to Start Multiple Appium Instances

Starting Appium services manual via terminal or batch scripts is inefficient. This article demonstrates how to automate launhcing multiple Appium servers using Python's subprocess and multiprocessing modules, enabling multi-device test execution in parallel.

Launching a Single Appium Instance with subprocess

The subprocess module allows spawning new processes, capturing their output, and retrieving return codes. Below, we define a function that starts an Appium server on a given host and port, and writes logs to a file.

# single_appium.py
import subprocess
from time import ctime

def start_appium(server_ip, server_port):
    # The bootstrap port is used for communication between Appium and the device
    device_port = str(server_port + 1)
    cmd = f'start /b appium -a {server_ip} -p {server_port} -bp {device_port}'

    print(f'{cmd} at {ctime()}')
    log_path = f'../logs/{server_port}.log'
    subprocess.Popen(cmd, shell=True, stdout=open(log_path, 'a'), stderr=subprocess.STDOUT)

if __name__ == '__main__':
    start_appium('127.0.0.1', 4723)

To verify success, check for the process using netstat -ano | findstr 4723 and confirm that 4723.log is created in the logs directory. To stop an Appium process, run taskkill -f -pid <PID>.

Starting Multiple Instances Sequentially

The previous code starts only one instance. By looping over port numbers, we can launch multiple servers sequentially (not concurrently). Each server uses consecutive even ports: 4723, 4725, etc., with corresponding bootstrap ports.

if __name__ == '__main__':
    for i in range(2):
        port = 4723 + 2 * i
        start_appium('127.0.0.1', port)

Concurrent Startup with multiprocessing

Sequential startup still creates servers one after another. To launch them in parallel, we use the multiprocessing module. Each Appium process is wrapped in a separate Process object, started simultaneously, then joined.

# concurrent_appium.py
import multiprocessing
import subprocess
from time import ctime

def start_appium(server_ip, server_port):
    device_port = str(server_port + 1)
    cmd = f'start /b appium -a {server_ip} -p {server_port} --bootstrap-port {device_port}'
    print(f'{cmd} at {ctime()}')
    log_path = f'./logs/{server_port}.log'
    subprocess.Popen(cmd, shell=True, stdout=open(log_path, 'a'), stderr=subprocess.STDOUT)

if __name__ == '__main__':
    processes = []
    for i in range(2):
        port = 4723 + 2 * i
        p = multiprocessing.Process(target=start_appium, args=('127.0.0.1', port))
        processes.append(p)

    # Start all processes concurrently
    for p in processes:
        p.start()
    # Wait for all to finish (Appium servers keep running)
    for p in processes:
        p.join()

This approach launches two Appium servers (ports 4723 and 4725) at the same time. Each server writes its own log file. Using multiprocessing optimizes boot time and is essential when scaling to many device.

Tags: appium python multiprocessing subprocess automated-testing

Posted on Fri, 12 Jun 2026 16:06:39 +0000 by pc-coholic