Raise Error Ebadf
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 errno 9 bad file descriptor python site About Us Learn more about Stack Overflow the company Business Learn socket bad file descriptor python more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x python bad file descriptor Dismiss Join the Stack Overflow Community 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 Python python socket close client / server question up vote 6 down vote favorite 2 I'm working on a bit of a project in python. I have a client and a server. The server listens for connections and once a connection is received it waits for input from the client. The idea is that the client can connect to the server and execute system commands such as ls
Ioerror: [errno 9] Bad File Descriptor
and cat. This is my server code: import sys, os, socket host = '' port = 50105 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((host, port)) print("Server started on port: ", port) s.listen(5) print("Server listening\n") conn, addr = s.accept() print 'New connection from ', addr while (1): rc = conn.recv(5) pipe = os.popen(rc) rl = pipe.readlines() file = conn.makefile('w', 0) file.writelines(rl[:-1]) file.close() conn.close() And this is my client code: import sys, socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) host = 'localhost' port = input('Port: ') s.connect((host, port)) cmd = raw_input('$ ') s.send(cmd) file = s.makefile('r', 0) sys.stdout.writelines(file.readlines()) When I start the server I get the right output, saying the server is listening. But when I connect with my client and type a command the server exits with this error: Traceback (most recent call last): File "server.py", line 21, in
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings
Python Socket Select
and policies of this site About Us Learn more about Stack Overflow python socket timeout the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation python socket example Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it http://stackoverflow.com/questions/4642345/python-client-server-question only takes a minute: Sign up Python Socket Programming - Bad file descriptor error up vote 1 down vote favorite I'm trying to create a simple server, and keep getting the following error in IDLE: File "C:\Python27\lib\socket.py", line 202, in accept sock, addr = self._sock.accept() File "C:\Python27\lib\socket.py", line 170, in _dummy raise error(EBADF, 'Bad file descriptor') error: [Errno 9] Bad http://stackoverflow.com/questions/28495956/python-socket-programming-bad-file-descriptor-error file descriptor This is my code. I've tried understanding why, and it has something to do with closing one of the sockets and then trying to use it again but I don't really get how I'm supposed to fix it. Any and all help is appreciated. :) from socket import * serverSocket = socket(AF_INET, SOCK_STREAM) port=10101 serverSocket.bind(('',port)) serverSocket.listen(5) while True: print 'Ready to serve...' connectionSocket, addr = serverSocket.accept() try: message = serverSocket.recv(1024) filename = message.split()[1] f = open(filename[1:]) outputdata = f.read() connectionSocket.send("HTTP/1.1 200 OK\r\n\n") for i in range(0, len(outputdata)): connectionSocket.send(outputdata[i]) connectionSocket.close() except IOError: connectionSocket.send('HTTP/1.1 404 File not found\r\n\n') connectionSocket.close() serverSocket.close() serverSocket.close() python sockets tcp share|improve this question asked Feb 13 '15 at 9:08 Gustaf Svensson 15819 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote A couple of things: As user27994550 put in his code, you want to use message = connectionSocket.recv(1024) to receive messages, not the server socket. The other thing that both of your codes missed is you don't want to call serverSocket.close() in your except function unless you're closing the prog
Sign in Pricing Blog Support Search GitHub This repository Watch 82 Star 1,080 https://github.com/abourget/gevent-socketio/issues/106 Fork 322 abourget/gevent-socketio Code Issues 74 Pull requests 26 https://github.com/benoitc/gunicorn/issues/602 Projects 0 Wiki Pulse Graphs New issue raise error(EBADF, 'Bad file descriptor') #106 Closed sontek opened this Issue Nov 21, 2012 · 4 comments Labels None yet Milestone No milestone Assignees No one assigned 1 participant bad file Collaborator sontek commented Nov 21, 2012 Commit 2e251ce broke gevent-socketio, now you get: raise error(EBADF, 'Bad file descriptor') File "/home/sontek/.virtualenvs/gevent-socketio/src/gevent/gevent/socket.py", line 215, in _dummy raise error(EBADF, 'Bad file descriptor') Collaborator sontek commented Nov 21, 2012 @abourget This was your commit, I'm going to dig in to figure out exactly bad file descriptor what caused it but figured you might have an idea. Collaborator sontek commented Nov 22, 2012 I've got a fix for websockets and flash sockets but it looks like the polling transports are broken as well Collaborator sontek commented Nov 22, 2012 The jsonp/xhr polling breakage is because of gevent 1.0, I'll make a new ticket for that. Collaborator sontek commented Nov 22, 2012 This is fixed in master. sontek closed this Nov 22, 2012 Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment Contact GitHub API Training Shop Blog About © 2016 GitHub, Inc. Terms Privacy Security Status Help You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Sign in Pricing Blog Support Search GitHub This repository Watch 203 Star 3,334 Fork 686 benoitc/gunicorn Code Issues 91 Pull requests 20 Projects 1 Pulse Graphs New issue Eventlet worker raises error: [Errno 9] Bad file descriptor on pypy #602 Closed sontek opened this Issue Aug 27, 2013 · 4 comments Labels None yet Milestone No milestone Assignees No one assigned 2 participants sontek commented Aug 27, 2013 Full call stack ERROR:gunicorn.error:Socket error processing request. Traceback (most recent call last): File "/home/sontek/.virtualenvs/helloworld_pypy/site-packages/gunicorn-17.5-py2.7.egg/gunicorn/workers/async.py", line 42, in handle req = six.next(parser) File "/home/sontek/.virtualenvs/helloworld_pypy/site-packages/gunicorn-17.5-py2.7.egg/gunicorn/http/parser.py", line 39, in __next__ self.mesg = self.mesg_class(self.cfg, self.unreader, self.req_count) File "/home/sontek/.virtualenvs/helloworld_pypy/site-packages/gunicorn-17.5-py2.7.egg/gunicorn/http/message.py", line 152, in __init__ super(Request, self).__init__(cfg, unreader) File "/home/sontek/.virtualenvs/helloworld_pypy/site-packages/gunicorn-17.5-py2.7.egg/gunicorn/http/message.py", line 49, in __init__ unused = self.parse(self.unreader) File "/home/sontek/.virtualenvs/helloworld_pypy/site-packages/gunicorn-17.5-py2.7.egg/gunicorn/http/message.py", line 164, in parse self.get_data(unreader, buf, stop=True) File "/home/sontek/.virtualenvs/helloworld_pypy/site-packages/gunicorn-17.5-py2.7.egg/gunicorn/http/message.py", line 155, in get_data data = unreader.read() File "/home/sontek/.virtualenvs/helloworld_pypy/site-packages/gunicorn-17.5-py2.7.egg/gunicorn/http/unreader.py", line 38, in read d = self.chunk() File "/home/sontek/.virtualenvs/helloworld_pypy/site-packages/gunicorn-17.5-py2.7.egg/gunicorn/http/unreader.py", line 65, in chunk return self.sock.recv(self.mxchunk) File "/home/sontek/.virtualenvs/helloworld_pypy/site-packages/eventlet-0.13.0-py2.7.egg/eventlet/greenio.py", line 251, in recv return fd.recv(buflen, flags) File "/usr/lib64/pypy-2.0.2/lib-python/2.7/socket.py", line 188, in recv return self._sock.recv(buffersize, flags=flags) error: [Errno 9] Bad file descriptor Example code to reproduce: https://github.com/sontek/pyramid_helloworld sontek commented Aug 27, 2013 It doesn't happen if you are only returning a response but if you have 2 assets like a favicon and a css fil