Python Forum
proc communicate not exiting on python subprocess timeout
Thread Rating:
  • 3 Vote(s) - 2.67 Average
  • 1
  • 2
  • 3
  • 4
  • 5
proc communicate not exiting on python subprocess timeout
#1
Hello,


the script below (a python process is called, which calls a waitfor cmd with a timeout of 4 seconds) is supposed to end after 4 seconds. But instead proc.communicate stops after the 20 seconds timeout.

Why???

import subprocess
if __name__ == "__main__":
  proc_str = ["C:\\Program Files (x86)\\Anaconda3\\Python.exe",
                        "-c", "import 
  subprocess;subprocess.run('cmd /S /C waitfor g /t 200', shell=False, timeout=4)"]
  proc = subprocess.Popen(proc_str,
                            stdin=subprocess.PIPE,
                            stderr=subprocess.PIPE,
                            stdout=subprocess.PIPE,
                            shell=False,
                            universal_newlines=True)
  (proc_out, proc_err) = proc.communicate(timeout=20)
  if (proc.returncode == 0):
     pass
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to communicate between Electron Framework and python Abdul_Rafey 0 232 Mar-09-2024, 12:18 PM
Last Post: Abdul_Rafey
  Generate lists of devices and partitions from /proc/partitions? DachshundDigital 1 782 Feb-28-2023, 10:55 PM
Last Post: deanhystad
  FTp timeout except korenron 2 3,595 Feb-01-2022, 06:51 AM
Last Post: korenron
  Conceptualizing modulus. How to compare & communicate with values in a Dictionary Kaanyrvhok 7 4,035 Mar-15-2021, 05:43 PM
Last Post: Kaanyrvhok
  Return not exiting function?? rudihammad 3 5,309 Dec-01-2020, 07:11 PM
Last Post: bowlofred
  python loop in subprocess vinothkumargomu 6 3,223 Jul-06-2020, 12:02 PM
Last Post: vinothkumargomu
  Visiting invisible folders in /proc anddontyoucomebacknomore 0 1,582 Mar-18-2019, 02:05 AM
Last Post: anddontyoucomebacknomore
  Problems parsing /proc folder anddontyoucomebacknomore 2 2,574 Mar-06-2019, 09:16 PM
Last Post: DeaD_EyE
  Multi-processing to communicate with microcontrollers Khoily 1 2,522 Mar-01-2019, 08:57 PM
Last Post: DeaD_EyE
  Python Error in subprocess.py roydianton90 1 5,598 Dec-14-2018, 11:26 AM
Last Post: jeanMichelBain

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020