I have a function that periodically pings IP. For this I use
subprocess to call os
In some extreame cases
ping cannot be started (not enough memory). When this happens it opens new window with this error. While the window is opened the function waits for it to complete.
So, my question is how to close it by timeout even if this window is opened.
async def ping(): try: proc = subprocess.Popen(['ping', '188.8.131.52'], stdout=subprocess.PIPE) result = proc.communicate(timeout=10) # I assume it freezes here if proc.returncode == 0: await process_result(result) # some processing of the result else: log_error(proc.returncode) except Exception as e: proc.kill() log_error(e)
OS: Windows 10