Python Bad File Descriptor Error
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 of this site About Us Learn more about Stack Overflow the company Business Learn bad file descriptor python socket more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags errno 9 bad file descriptor c Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, python print ioerror: [errno 9] bad file descriptor helping each other. Join them; it only takes a minute: Sign up Bad file descriptor error up vote 11 down vote favorite If I try executing the following code f = file('test','rb') fout = file('test.out','wb') for i in
Python Subprocess Oserror Errno 9 Bad File Descriptor
range(10): a = f.read(1) fout.write(a) f.close() f = fout f.seek(4) print f.read(4) Where 'test' is any arbitrary file, I get: Traceback (most recent call last): File "testbad.py", line 12, in
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 raise error(ebadf, 'bad file descriptor') more about Stack Overflow the company Business Learn more about hiring developers or
Connect:errno=9
posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community
Python Open File For Reading And Writing
Stack Overflow is a community of 6.2 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 http://stackoverflow.com/questions/2368967/bad-file-descriptor-error up vote 8 down vote favorite 3 My code is 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" http://stackoverflow.com/questions/15958026/getting-errno-9-bad-file-descriptor-in-python-socket python sockets share|improve this question asked Apr 11 '13 at 20:13 Mike Savi 881110 1 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 165k11198275 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 Na
here for a quick overview of the site Help Center Detailed answers to any questions you might http://stackoverflow.com/questions/16382899/python-socket-socket-error-bad-file-descriptor have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting https://bytes.com/topic/python/answers/40073-file-readlines-gives-me-error-bad-file-descriptor ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 bad file 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 the socket and splits it using the delimiter $. But I am unable to bad file descriptor 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
help? Post your question and get tips & solutions from a community of 418,626 IT Pros & Developers. It's quick & easy. file.readlines() - gives me error (bad file descriptor) P: n/a wordsender Hey guys, I can't figure this one out, why is this simple script giving me problems? logfile=file(r'test.txt','w') logfile.write('datetime') test=logfile.readlines() When I run it I get the error message: Traceback (most recent call last): File "C:\Documents and Settings\Gregory\My Documents\Get New Great Job\testfile.py", line 3, in ? test=logfile.readlines() IOError: [Errno 9] Bad file descriptor I'm running Windows XP, Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] on win32 Any help would be greatly appricated. Thanks, Greg Jul 18 '05 #1 Post Reply Share this Question 9 Replies P: n/a Aldo Cortesi Thus spake wo********@gmail.com (wo********@gmail.com): Hey guys, I can't figure this one out, why is this simple script giving me problems? logfile=file(r'test.txt','w') ^^^ You've opened the file in write mode. To read from the file, you'll have to reopen it in read mode ("r"). Also, if the file you're dealing with really is a log file, you probably want don't want to open it in write mode for writing information either, since that will truncate the file and lose previously logged information. Try append mode ("a") instead. Cheers, Aldo -- Aldo Cortesi al**@nullcube.com http://www.nullcube.com Off: (02) 9283 1131 Mob: 0419 492 863 Jul 18 '05 #2 P: n/a Gurpreet Sachdeva I tried logfile=file(r'test.txt','w+') logfile.write('datetime') test=logfile.readlines() print test I got : Open an encoded file using the given mode and return a wrapped version providing transparent encoding/decoding. Note: The wrapped version will only accept the object format defined by the codecs, i.e. Unicode objects for most builtin codecs. Output is also codec dependent and will usually by Unicode as well. Files are always opened in binary mode, even if no binary mo