Bad File Descriptor Error In Python
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies python ioerror bad file descriptor of this site About Us Learn more about Stack Overflow the company Business python bad file descriptor socket Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask
Python Write Bad File Descriptor
Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign
Bad File Descriptor Error In C
up What can lead to “IOError: [Errno 9] Bad file descriptor” during os.system()? up vote 27 down vote favorite 2 I am using a scientific software including a Python script that is calling os.system() which is used to run another scientific program. While the subprocess is running, Python at some point prints the following: close failed in file object destructor: IOError: [Errno errno 9 bad file descriptor python 9] Bad file descriptor I believe that this message is printed at the same time as os.system() returns. My questions now are: Which conditions can lead to this type of IOError? What does it exactly mean? What does it mean for the subprocess that has been invoked by os.system()? python subprocess posix file-descriptor ioerror share|improve this question edited Apr 24 at 0:10 Aminah Nuraini 2,0491226 asked Oct 7 '11 at 10:54 Jan-Philip Gehrcke 13.4k14073 1 Note: using the subprocess module is preferable over os.system(). –Petr Viktorin Oct 7 '11 at 11:07 :-) I know that and there is a lot of non-perfect stuff in this software. –Jan-Philip Gehrcke Oct 7 '11 at 11:15 add a comment| 2 Answers 2 active oldest votes up vote 22 down vote accepted You get this error message if a Python file was closed from "the outside", i.e. not from the file object's close() method: >>> f = open(".bashrc") >>> os.close(f.fileno()) >>> del f close failed in file object destructor: IOError: [Errno 9] Bad file descriptor The line del f deletes the last reference to the file object
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the
Python Subprocess Oserror Errno 9 Bad File Descriptor
company Business Learn more about hiring developers or posting ads with us Stack Overflow bad file descriptor python print Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 ioerror: [errno 9] bad file descriptor print million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Getting Errno 9: Bad file descriptor in python socket up vote 8 down vote favorite 3 My code is http://stackoverflow.com/questions/7686275/what-can-lead-to-ioerror-errno-9-bad-file-descriptor-during-os-system this: while 1: # Determine whether the server is up or down try: s.connect((mcip, port)) s.send(magic) data = s.recv(1024) s.close() print data except Exception, e: print e sleep(60) It works fine on the first run, but gives me Errno 9 every time after. What am I doing wrong? BTW, mcip = "mau5ville.com" port = 25565 magic = "\xFE" python sockets share|improve this question asked Apr 11 '13 at 20:13 Mike Savi 881110 1 http://stackoverflow.com/questions/15958026/getting-errno-9-bad-file-descriptor-in-python-socket What do magic, mcip, and port mean? Please post the full code on www.pastebin.com –xxmbabanexx Apr 11 '13 at 20:15 Added them for you –Mike Savi Apr 11 '13 at 20:17 add a comment| 1 Answer 1 active oldest votes up vote 19 down vote accepted You're calling connect on the same socket you closed. You can't do that. As for the docs for close say: All future operations on the socket object will fail. Just move the s = socket.socket() (or whatever you have) into the loop. (Or, if you prefer, use create_connection instead of doing it in two steps, which makes this harder to get wrong, as well as meaning you don't have to guess at IPv4 vs. IPv6, etc.) share|improve this answer answered Apr 11 '13 at 20:18 abarnert 164k9196269 Awesomeee. Thanks! –Mike Savi Apr 11 '13 at 20:20 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged python sockets or
here for a quick overview of the site Help Center Detailed answers http://stackoverflow.com/questions/16382899/python-socket-socket-error-bad-file-descriptor to any questions you might have Meta Discuss the workings http://www.gossamer-threads.com/lists/python/python/844558 and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack bad file Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Python socket (Socket Error Bad File Descriptor) up vote 9 down vote favorite The following receiveFile() function reads a filename and file data from bad file descriptor the socket and splits it using the delimiter $. But I am unable to close the socket and a Bad file descriptor error is raised. If I comment out the self.server_socket.close() statement then there is no error but the socket is listening forever. Code:- def listen(self): self.server_socket.listen(10) while True: client_socket, address = self.server_socket.accept() print 'connected to', address self.receiveFile(client_socket) def receiveFile(self,sock): data = sock.recv(1024) data = data.split("$"); print 'filename', data[0] f = open(data[0], "wb") #data = sock.recv(1024) print 'the data is', data[1] f.write(data[1]) data = sock.recv(1024) while (data): f.write(data) data=sock.recv(1024) f.close() self.server_socket.close() print 'the data is', data print "File Downloaded" Traceback:- Traceback (most recent call last): File "server.py", line 45, in
Post #1 of 11 (7429 views) Permalink Errno 9] Bad file descriptor I get sometimes a Errno 9 Bad file descriptor the code is too long to show it here but what are the circumstances this could happen? A web search showed nothing. I have especially the feeling Python 2.6 has some problems with Unicode ... and might not find the file. Is that possible? -- http://mail.python.org/mailman/listinfo/python-list steve-REMOVE-THIS at cybersource Jul11,2010,8:11PM Post #2 of 11 (7288 views) Permalink Re: Errno 9] Bad file descriptor [In reply to] On Sun, 11 Jul 2010 17:48:40 -0700, joblack wrote: > I get sometimes a > > Errno 9 Bad file descriptor > > the code is too long to show it here You can at least show the actual line that fails. Are you trying to open a file, a named socket, a pipe or a device? > but what are the circumstances this > could happen? A web search showed nothing. The first two google hits for "bad file descriptor" seem pretty relevant to me: http://linux.sys-con.com/node/1053821 http://lists.freebsd.org/pipermail/freebsd-questions/2003-June/009583.html > I have especially the feeling Python 2.6 has some problems with Unicode > ... and might not find the file. Is that possible? Possible, but you should get Errno 2 No such file or directory not bad file descriptor. If you're trying to open a file, you have a broken file system and need to run fsck or equivalent. If it's a pipe or socket or something, you need to tell us what it is. -- Steven -- http://mail.python.org/mailman/listinfo/python-list timr at probo Jul12,2010,11:15PM Post #3 of 11 (7279 views) Permalink Re: Errno 9] Bad file descriptor [In reply to] joblack