[Python] Timeout when I try an action with Python subprocess but when I run it manually throw...

Discussão em 'Python' iniciado por Stack, Fevereiro 16, 2025.

  1. Stack

    Stack Membro Participativo

    I have this function which is trying to restart a genymotion device in python:

    def restart_device(d, stop_timeout=40, start_timeout=30):
    """Restarts a specific Genymotion device with timeouts and logs the process."""
    try:
    device_name = get_device_name_by_ip(d.serial)
    logging.info(f"Stopping device: {device_name}")
    subprocess.run([gmtoolPath, "admin", "stop", device_name], check=True, timeout=stop_timeout)
    time.sleep(5) # Wait a bit before restarting

    logging.info(f"Starting device: {device_name}")
    subprocess.run([gmtoolPath, "admin", "start", device_name], check=True, timeout=start_timeout)

    # Wait for the device to boot up
    logging.info(f"Waiting for device {device_name} to boot...")
    time.sleep(30) # Adjust the wait time as needed
    logging.info(f"Device {device_name} restarted successfully.")
    except subprocess.CalledProcessError as e:
    logging.error(f"Error restarting device {device_name}: {e.stderr}")
    except subprocess.TimeoutExpired as e:
    logging.error(f"Timeout expired while restarting device {device_name}: {e}")


    When I run the it throw the code its returning timeout but when I run the stop and start commands manually with the termianl its working perfectly.

    Also an important note, I have another computer and when I run the exact same code its working fine on it.

    Any help will be helpfull :)

    Continue reading...

Compartilhe esta Página