File: test.py

package info (click to toggle)
mosquitto 2.0.22-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,572 kB
  • sloc: ansic: 51,107; python: 15,095; xml: 7,187; makefile: 1,821; cpp: 1,541; sh: 320; perl: 70
file content (46 lines) | stat: -rwxr-xr-x 1,053 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3

import subprocess
import time
import sys

def next_client(clients):
    if len(clients) == 0:
        return

    c = clients.pop()
    args = ["./random_client.py", str(c)]

    proc = subprocess.Popen(args, stderr=subprocess.DEVNULL)
    proc.cid = c
    return proc


def run_clients(max_clients):
    clients = list(range(1, max_clients))
    start_time = time.time()

    running_clients = []
    while True:
        print(len(running_clients))
        if len(running_clients) < max_clients:
            c = next_client(clients)
            if c is not None:
                running_clients.append(c)
        else:
            time.sleep(0.1)

        for c in running_clients:
            c.poll()
            if c.returncode is not None:
                running_clients.remove(c)
                clients.append(c.cid)
                c.terminate()
                c.wait()


env = {}
env["LD_LIBRARY_PATH"] = "../../lib"

#broker = subprocess.Popen(["../../src/mosquitto", "-c", "random.conf"], env=env)
run_clients(1000)