What Causes The “Ioerror: [Errno 9] Bad File Descriptor” During Os.System()?

483    Asked by ChrisEVANS in Tableau , Asked on Aug 2, 2023

Currently, I am deploying os.system(). It is a scientific software containing a python script, meant to execute a different scientific program. There is another way, a subprocess, that will run and Python will give the below-mentioned code:

close failed in file object destructor:
IOError: [Errno 9] Bad file descriptor

This message will be printed at the time as os.system(). So, which condition will lead to such an IOError?

Answered by Chris EVANS
This error “oserror: [errno 9] bad file descriptor’ message occurs when python file was closed externally, and not from the file objects close ().>>> f = open (“bashrc”)
>>>os.close (f.fileno())
>>>del f
Close failed in file object destructor:
IOError : [Errno 9] Bad file descriptor

In the given code, del f line will erase the last reference to the file object. Finally file._del_ will be invoked.

The internal condition depicts that the file is yet open as f.close() was never invoked. Hence, anyone who attempts to close the file is the destructor. OS gives the error message owing to trying to close the file that was not open. As os.system90 do not make any python file object, it does not resemble system() call that was the root of the error. The cause of receiving the error “oserror: [errno 9] bad file descriptor”:

The internal condition of the file object shows that the file is yet open, as f.close() was not invoked. Hence, the destructor attempts to close that file. The OS simultaneously gives the error message due to attempting to close the file that is not open.

However, the error message can also be seen in case the Ransomware Protection is activated on the working directory. Windows prohibit any third party applications to alter the files if the directory is secured by Ransomware Protection that comes with windows. To correct this, go to Windows Security - > Virus and Threat Protection - > Manage Ransomware Protection - > Allow an app through controlled folder access” . Finally add “Python [version] . exe” by tapping Add an allowed app.

The Tableau Training & Certification at JanBask Training offers experience like offline classes, saving students from the hassle of traveling to the physical location. The training provides a total Tableau discipline preparation by teaching the core concept and techniques that the job role demands. The training also gives extensive training to impart fundamental and advanced concepts through interesting e-tools and expert-led Tableau classes. Furthermore, JanBask Training helps you get job-ready and face the tough competitive market with confidence.



Your Answer

Interviews

Parent Categories