Форум сайта python.su
Такой код:
import re import random import string from subprocess import Popen import subprocess from threading import Thread import os.path import time results = [] start_processes = 6 # количество одновременно выполняющихся процессов def run_command(result_storage): # запуск ping while True: S = [3, 4] S = random.choice(S) # number of characters in the string. ran = ''.join(random.choices(string.digits, k = S)) #print(ran) cmd = str( subprocess.check_output( ['ping', '-c', f'{ran}', 'google.' + 'com'], text=True ) ) result_storage.append(cmd) threads = [] # поддержание определенного количества одновременно запущенных процессов for _ in range(start_processes): t = Thread(target=run_command, args=[results]) t.start() threads.append(t) for t in threads: t.join()
ping: google.com: Temporary failure in name resolution Exception in thread Thread-4 (run_command): Traceback (most recent call last): File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner self.run() File "/usr/lib/python3.10/threading.py", line 953, in run self._target(*self._args, **self._kwargs) File "/media/sf_soft/vsc/test2.py", line 21, in run_command subprocess.check_output( File "/usr/lib/python3.10/subprocess.py", line 421, in check_output return run(*popenargs, stdout=PIPE, timeout=timeout, check=True, File "/usr/lib/python3.10/subprocess.py", line 526, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command '['ping', '-c', '150', 'google.com']' returned non-zero exit status 2.
Отредактировано gelius (Март 15, 2023 20:31:02)
Офлайн
https://stackoverflow.com/questions/921398/exit-status-of-ping-command
P.S. ты пытаешься пингами гугл задудосить чтоле
# Life loop while alive: if (fun > boredom) and money: pass_day(fun, boredom, money) continue else: break
Офлайн