Error Bad File Descriptor Python
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you python ioerror bad file descriptor might have Meta Discuss the workings and policies of this
Python Bad File Descriptor Socket
site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or
Python Write Bad File Descriptor
posting 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
Errno 9 Bad File Descriptor Python
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 the socket and splits it using the delimiter $. But I bad file descriptor python print 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
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 python subprocess oserror errno 9 bad file descriptor Learn more about Stack Overflow the company Business Learn more about hiring developers ioerror: [errno 9] bad file descriptor print or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack raise error(ebadf, 'bad file descriptor') 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 why am I getting IOError: (9, 'Bad file http://stackoverflow.com/questions/16382899/python-socket-socket-error-bad-file-descriptor descriptor') error while making print statements? up vote 14 down vote favorite 4 I am running a python2.5 script on a windows 2003 server as a service. I am getting this error for simple print statments: IOError: (9, 'Bad file descriptor') I deleted all the print statements because they were only used for development purposes, but I am unsure why a print statement would cause me any http://stackoverflow.com/questions/4230855/why-am-i-getting-ioerror-9-bad-file-descriptor-error-while-making-print-st greif. I ran the same script not as a service without any major problems. Just wondering if anyone else has any insight? python windows service share|improve this question asked Nov 20 '10 at 2:16 Richard 3,379185087 add a comment| 2 Answers 2 active oldest votes up vote 21 down vote accepted You can't print because sys.stdout is not available when not running as a console session. Instead of using print statements you can consider using the logging module so you can set the loglevel and write all critical things to the system event log. It should be noted that you can still get it to work (or silently ignore the problem) by doing something like this: To write to a file per output stream: import sys sys.stdout = open('stdout.txt', 'w') sys.stderr = open('stderr.txt', 'w') To write to a single file: import sys sys.stdout = sys.stderr = open('output.txt', 'w') Or to silently ignore all print statements: import sys class NullWriter(object): def write(self, value): pass sys.stdout = sys.stderr = NullWriter() share|improve this answer edited Mar 13 at 16:35 Braiam 3,27582656 answered Nov 20 '10 at 2:19 Wolph 42.6k673105 7 More specifically, the first three file descriptors (corresponding to stdin, std
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 http://stackoverflow.com/questions/15958026/getting-errno-9-bad-file-descriptor-in-python-socket 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 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 Getting bad file Errno 9: Bad file descriptor in python socket 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 bad file descriptor 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 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 164k9197272 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