Forums

Recurring Issue: OSError: [Errno 9] Bad file descriptor in server.log

Description: Hello everyone,

I'm facing a persistent issue with my application on PythonAnywhere. Sometimes it works correctly, but other times it fails, and in the log file (server.log) I repeatedly encounter the following error:

2024-05-13 22:59:25 --- Logging error ---
2024-05-13 22:59:25 Traceback (most recent call last):
2024-05-13 22:59:25   File "/usr/local/lib/python3.10/logging/handlers.py", line 989, in emit#012    self.socket.sendto(msg, self.address)
2024-05-13 22:59:25 OSError: [Errno 9] Bad file descriptor
2024-05-13 22:59:25 #012During handling of the above exception, another exception occurred:
2024-05-13 22:59:25 Traceback (most recent call last):
2024-05-13 22:59:25   File "/usr/local/lib/python3.10/logging/handlers.py", line 989, in emit#012    self.socket.sendto(msg, self.address)
2024-05-13 22:59:25 OSError: [Errno 9] Bad file descriptor
...

I've searched online and haven't found anyone else who has experienced this specific error. Could someone here help me understand why this is happening and how I can fix it?

I appreciate any help or advice you can offer.

Thanks in advance!

Are you calling djanog.setup in your code? That could be causing it (see this help page as well).