Python Socket.error Errno 11 Resource Temporarily Unavailable
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 errno 11 resource temporarily unavailable python Stack Overflow the company Business Learn more about hiring developers or posting ads with
Python Socket Recv Resource Temporarily Unavailable
us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is error: [errno 11] resource temporarily unavailable gunicorn a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Creating non-blocking socket in python up vote 1 down vote favorite I was
Python Socket Resource Temporarily Unavailable
trying to understand how non-blocking sockets work ,so I wrote this simple server in python . import socket s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(('127.0.0.1',1000)) s.listen(5) s.setblocking(0) while True: try: conn, addr = s.accept() print ('connection from',addr) data=conn.recv(100) print ('recived: ',data,len(data)) except: pass Then I tried to connect to this server from multiple instances of this client import socket s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('127.0.0.1',1000)) while True: continue But for some reason putting blocking to 0 or python resource temporarily unavailable 1 dose not seem to have an effect and server's recv method always block the execution. So, dose creating non-blocking socket in python require more than just setting the blocking flag to 0. python sockets nonblocking share|improve this question asked Aug 21 '14 at 12:32 Gray 378 add a comment| 2 Answers 2 active oldest votes up vote 3 down vote accepted setblocking only affects the socket you use it on. So you have to add conn.setblocking(0) to see an effect: The recv will then return immediately if there is no data available. share|improve this answer edited Aug 21 '14 at 13:27 answered Aug 21 '14 at 12:37 Phillip 10.6k923 setblocking(0) does affect socket.accept() which will not block waiting for an incoming connection, but raise an exception. –mhawke Aug 21 '14 at 12:51 The documentation seems to be incomplete here, you are of course right. I've removed that comment from my answer. But there is an exception to this: If socket.settimeout is used, Python will still call select(2) before accept(2), i.e. wait at least until the timeout is reached. –Phillip Aug 21 '14 at 13:26 add a comment| up vote 0 down vote You just need to call setblocking(0) on the connected socket, i.e
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings
Blockingioerror: [errno 11] Resource Temporarily Unavailable
and policies of this site About Us Learn more about Stack Overflow
Python Socket Settimeout
the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation python non blocking socket 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/25426447/creating-non-blocking-socket-in-python only takes a minute: Sign up Python error: “socket.error: [Errno 11] Resource temporarily unavailable” when sending image up vote 1 down vote favorite I want to make a program that accesses images from files, encodes them, and sends them to an server. Than the server is supposed to decode the image, and save it to file. I tested the image http://stackoverflow.com/questions/39145357/python-error-socket-error-errno-11-resource-temporarily-unavailable-when-s encoding itself, and it worked, so the problem lies in the server and client connection. Here is the server: import socket import errno import base64 from PIL import Image import StringIO def connect(c): try: image = c.recv(8192) return image except IOError as e: if e.errno == errno.EWOULDBLOCK: connect(c) def Main(): host = '138.106.180.21' port = 12345 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) s.bind((host, port)) s.listen(1) while True: c, addr = s.accept() c.setblocking(0) print "Connection from: " + str(addr) image = c.recv(8192)#connect(c) imgname = 'test.png' fh = open(imgname, "wb") if image == 'cusdom_image': with open('images.png', "rb") as imageFile: image = '' image = base64.b64encode(imageFile.read()) print image fh.write(image.decode('base64')) fh.close() if __name__ == '__main__': Main() And here is the client: import socket import base64 from PIL import Image import StringIO import os, sys ip = '138.106.180.21' port = 12345 print 'Add event executed' s = socket.socket() s.connect((ip, port)) image_path = '/home/gilgamesch/Bilder/Bildschirmfoto.png' print os.getcwd() olddir = os.getcwd() os.chdir('/') print os.getcwd() if image_path != '': with open(image_path, "rb") as imageFile: image_data = base64.b64encode(imageFile.read()) print 'open worked' else: image_data = 'cusdom_image' os.chdir(olddir) s.send(image_data) s.
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings http://stackoverflow.com/questions/13340893/oserror-errno-11-resource-temporarily-unavailable-what-causes-this 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 https://gist.github.com/2056748 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 resource temporarily only takes a minute: Sign up OSError: [Errno 11] Resource temporarily unavailable. What causes this? up vote 4 down vote favorite Background I have two python processes that need to communicate with each other. The comminication is handled by a class named Pipe. I made a seperate class for this because most of the information that needs to be communicated resource temporarily unavailable comes in the form of dictionaries so Pipe implements a pretty simple protocol for doing this. Here is the Pipe constructor: def __init__(self,sPath): """ create the fifo. if it already exists just associate with it """ self.sPath = sPath if not os.path.exists(sPath): try: os.mkfifo(sPath) except: raise Exception('cannot mkfifo at path \n {0}'.format(sPath)) self.iFH = os.open(sPath,os.O_RDWR | os.O_NONBLOCK) self.iFHBlocking = os.open(sPath,os.O_RDWR) So ideally I would just construct a Pipe in each process with the same path and they would be able to talk nice. I'm going to skip out stuff about the protocol because I think it is largely unnecessary here. All read and write operations make use of the following 'base' functions: def base_read_blocking(self,iLen): self.lock() lBytes = os.read(self.iFHBlocking,iLen) self.unlock() return lBytes def base_read(self,iLen): print('entering base read') self.lock() lBytes = os.read(self.iFH,iLen) self.unlock() print('exiting base read') return lBytes def base_write_blocking(self,lBytes): self.lock() safe_write(self.iFHBlocking,lBytes) self.unlock() def base_write(self,lBytes): print('entering base write') self.lock() safe_write(self.iFH,lBytes) self.unlock() print('exiting base write') safe_write was suggested in another post def safe_write(*args, **kwargs): while True: try: return os.write(*args, **kwargs) except OSError as e: if e.errno == 35: import time print(".") time.sl
a GitHub account Sign in Create a gist now Instantly share code, notes, and snippets. Star 1 Fork 0 techtonik/socket-client-server.py Created Mar 17, 2012 Embed What would you like to do? Embed Embed this gist in your website. Embed Share Copy sharable URL for this gist. Share Clone via HTTPS Clone with Git or checkout with SVN using the repository's web address. HTTPS Learn more about clone URLs Download ZIP Code Revisions 1 Stars 1 Python - socket - Client/server example in one thread Raw socket-client-server.py import socket if __name__ == '__main__': # socket read/write testing - client and server in one thread # (techtonik): the stuff below is placed into public domain print "-- Testing standard Python socket interface --" address = ("127.0.0.1", 9999) server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.setblocking(0) server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) server.bind( address ) server.listen(2) client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client.connect( address ) client.send("data to be catched") # accepted server socket is the one we can read from # note that it is different from server socket accsock, addr = server.accept() print '..got "%s" from %s' % (accsock.recv(4096), addr) client.send("more data for recv") print '..got "%s" from %s' % (accsock.recv(4096), addr) # accsock.close() # client.send("more data for recv") #socket.error: [Errno 9] Bad file descriptor # accsock, addr = server.accept() #socket.error: [Errno 11] Resource temporarily unavailable client.close() server.close() 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.