What can lead to “IOError: [Errno 9] Bad file descriptor” during os.system()?

18.6K    Asked by MayankMistry in Tableau , Asked on Jun 7, 2021

I'm using os.system(), which is a scientific software including a python script, used to run another scientific program. There's a subprocess, which will be running and python will print the following:

close failed in file object destructor:
IOError: [Errno 9] Bad file descriptor
Even this message will be printed at the same time as os.system()?

But my question is, Which condition will lead to this type of IOError? What is it? 

Answered by Ayushi Khatri

You get this kind of error “oserror: [errno 9] bad file descriptor” message only if python file was closed from the outside, i.e.,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 above code, del f line will delete the last reference to the file object, Ultimately file.__del__ will be called.

The Internal state indicates that the file is still open since f.close() was never called, So here someone tries to close the file, that someone is a destructor here. Later, OS throws an error because of the attempt for closing the file, which is not open.

Since os.system() does not create any python file object, It doesn't look like system() call was the origin of the error

Reason for getting error “oserror: [errno 9] bad file descriptor” :

The internal state of the file object indicates the file is still open since f. close() was never called, so the destructor tries to close the file. The OS subsequently throws an error because of the attempt to close a file that's not open.



Your Answer

Answer (1)

In most cases, tracing a stolen gift card can be challenging. Gift cards are typically treated as cash, and once they are stolen, it's difficult to track their usage or determine who has used them.


However, some gift card issuers may have systems in place to track and monitor gift card transactions. These systems might include:

Activation and Purchase Logs: Some gift card issuers keep records of when gift cards are activated and purchased. This information could potentially be used to track the initial transaction.

Redemption Logs: Some retailers or gift card issuers may track the redemption of gift cards when they are used to make purchases. This can provide insight into where and when the stolen gift card was used.

Fraud Monitoring: Many companies have fraud monitoring systems in place that can flag suspicious transactions, such as multiple purchases with the same gift card or purchases made in different geographic locations within a short period.

Cooperation with Law Enforcement: In cases of significant theft or fraud, gift card issuers may work with law enforcement agencies to investigate and potentially track down perpetrators.

Despite these measures, tracing a stolen gift card is often difficult, especially if it's been used shortly after being stolen. It's essential to report the theft to the gift card issuer and provide any relevant information, such as the card's serial number and purchase details, to assist with their investigation. Additionally, contacting local law enforcement authorities can be helpful in documenting the theft and potentially recovering lost funds.

6 Months

Interviews

Parent Categories