'Sometimes throws Bad file descriptor error, sometimes doesn't

The following piece of code was working fine for a year, of late it intermittently started failing with following error, wonder if any OS or hardware change is causing this

import subprocess
def bash_command(cmd):
    process = subprocess.Popen(cmd, shell=True, executable="/bin/bash")
    process.wait()

bash_command("bash myscript.sh")

The error message is:

Traceback (most recent call last):   File
"/Users/ishandutta2007/Documents/Projects/p2/shell_way/all_in_one_refill.py",
line 68,
    bash myscript.sh   File "/Users/ishandutta2007/Documents/Projects/p2/shell_way/all_in_one_refill.py",
line 31, in bash_command
    process = subprocess.Popen(cmd, shell=True, executable="/bin/bash")   File
"/Users/ishandutta2007/.pyenv/versions/3.6.0/lib/python3.6/subprocess.py",
line 707, in __init__
    restore_signals, start_new_session)   File "/Users/ishandutta2007/.pyenv/versions/3.6.0/lib/python3.6/subprocess.py",
line 1326, in _execute_child
    raise child_exception_type(errno_num, err_msg) OSError: [Errno 9] Bad file descriptor


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source