Socket.timeout: the Read Operation Timed Out in Python
Python socket.timeout() Examples
The post-obit are thirty code examples for showing how to use socket.timeout() . These examples are extracted from open source projects. Yous can vote up the ones you like or vote down the ones you don't like, and get to the original projection or source file by following the links above each example.
You lot may check out the related API usage on the sidebar.
You lot may besides want to check out all available functions/classes of the module socket , or try the search function .
Example 1
def jenkins(url, port): try: cli_port = False ctx = ssl.create_default_context() ctx.check_hostname = Fake ctx.verify_mode = ssl.CERT_NONE try: output = urllib2.urlopen('https://'+url+':'+port+"/jenkins/", context=ctx, timeout=8).info() cli_port = int(output['X-Jenkins-CLI-Port']) except urllib2.HTTPError, e: if e.getcode() == 404: effort: output = urllib2.urlopen('https://'+url+':'+port, context=ctx, timeout=8).info() cli_port = int(output['X-Jenkins-CLI-Port']) except: pass except: pass
Example 2
def connect(self): if self.is_server: log.debug("waiting for client to connect...") southward = socket.socket(socket.AF_INET, socket.SOCK_STREAM) southward.demark(('', self.port)) south.settimeout(0.1) start_time = time.time() s.listen(0) while True: try: conn, _ = southward.accept() self.conn = conn break except socket.timeout: laissez passer if self.timeout > 0 and time.time() - start_time >= self.timeout: s.close() raise RuntimeError("Timeout exceeded (%ds)" % self.timeout) cocky.conn.setblocking(True) else: log.debug("connecting to server (%s:%d)...", cocky.ip, self.port) self.conn = socket.create_connection((cocky.ip, self.port), cocky.timeout)
Example 3
def interface_listener_thread(s, baddr, port): southward.settimeout(x) mygeneration = generation while True: try: conn, addr = s.accept() except socket.timeout: if mygeneration == generation: proceed else: output('XX', 'INFO: Listener terminating for ' + baddr + ':' + str(port)) return fromto = addr[0] + ':' + str(addr[1]) + '->' + baddr + ':' + str(port) #print 'New connection on ' + baddr + ':' + str(port) + ' from ' + addr[0] + ':' + str(addr[ane]) threading.Thread(target=interface_thread , args=(conn, fromto)).start() # on-demand thread to swallow data
Example 4
def sendHciCommand(self, opcode, data, timeout=2): """ Send an arbitrary HCI packet past pushing a ship-task into the sendQueue. This function blocks until the response is received or the timeout expires. The render value is the Payload of the HCI Control Consummate Event which was received in response to the control or None if no response was received within the timeout. """ queue = Queue.Queue(i) try: self.sendQueue.put((opcode, data, queue), timeout=timeout) return queue.become(timeout=timeout) except Queue.Empty: log.warn("sendHciCommand: waiting for response timed out!") return None except Queue.Total: log.warn("sendHciCommand: ship queue is total!") return None
Example 5
def recvPacket(cocky, timeout=None): """ This role polls the recvQueue for the next available HCI packet and returns it. The function checks whether it is called from the sendThread or whatever other thread and respectively chooses either the sendThreadrecvQueue or the recvQueue. The recvQueue is filled past the recvThread. If the queue fills up the recvThread empties the queue (unprocessed packets are lost). The recvPacket function is meant to receive raw HCI packets in a blocking mode. Consider using the registerHciCallback() functionality as an alternative which works asynchronously. """ if not cocky.check_running(): return None try: return self.recvQueue.get(timeout=timeout) except Queue.Empty: render None
Example 6
def getreview(domain, cityid, activity, reviewid, timeout, maxretries, basepath, strength, pause): baseurl = 'http://world wide web.tripadvisor.' + domain + '/ShowUserReviews-grand' reviewurl = '%s%s-d%s-r%s' % (baseurl, cityid, action, reviewid) path = bone.sep.join((basepath, domain, str(cityid), str(activity))) filename = bone.sep.join((path, str(reviewid) + '.html')) if force or not os.path.exists(filename): htmlpage = download_page(reviewurl, maxretries, timeout, pause) if htmlpage is None: print('Error downloading the review URL: ' + reviewurl) else: if not os.path.exists(path): os.makedirs(path) with codecs.open up(filename, mode='w', encoding='utf8') equally file: file.write(htmlpage.decode('utf-8'))
Example seven
def check(self): try: mutual.internal_print("Checking module on server: {0}".format(self.get_module_name())) server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.settimeout(iii) server_socket.connect((cocky.config.become("Global", "remoteserverip"), int(self.config.get(cocky.get_module_configname(), "serverport")))) client_fake_thread = TCP_generic_thread(0, 0, None, None, server_socket, None, self.authentication, cocky.encryption_module, cocky.verbosity, self.config, cocky.get_module_name()) client_fake_thread.do_check() client_fake_thread.communication(True) cocky.cleanup(server_socket) except socket.timeout: common.internal_print("Checking failed: {0}".format(self.get_module_name()), -1) self.cleanup(server_socket) except socket.error as exception: if exception.args[0] == 111: common.internal_print("Checking failed: {0}".format(self.get_module_name()), -i) else: common.internal_print("Connectedness error: {0}".format(self.get_module_name()), -i) self.cleanup(server_socket) render
Instance 8
def __init__(self): super(ICMP, self).__init__() self.icmp = ICMP_Proto() self.ICMP_sequence = 0 # identifier lottery cocky.ICMP_identifier = int(random.random() * 65535) # serverport lottery, not like it matters cocky.ICMP_fake_serverport = int(random.random() * 65535) # prefix to brand it easier to detect xfl packets self.ICMP_prefix = "XFL" self.timeout = 2.0 # if the recv-sent>threshold: self.TRACKING_THRESHOLD = 50 # then we cutting dorsum the divergence with conform: self.TRACKING_ADJUST = 20 return
Example 9
def check(self): try: common.internal_print("Checking module on server: {0}".format(self.get_module_name())) server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.server_tuple = (self.config.get("Global", "remoteserverip"), int(self.config.get(self.get_module_configname(), "serverport"))) cocky.comms_socket = server_socket cocky.serverorclient = 0 self.authenticated = False cocky.do_check() self.communication(Truthful) except KeyboardInterrupt: self.cleanup() raise except socket.timeout: common.internal_print("Checking failed: {0}".format(self.get_module_name()), -1) except socket.error: self.cleanup() raise self.cleanup() return
Example 10
def transport(cmd): s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) s.settimeout(ane) flag = Simulated for i in range(three): try: s.sendto(cmd, addr) while one: data, a = s.recvfrom(1024) if 'ok' in information: flag = True break except socket.timeout: go on except: break if flag: break southward.close() return flag
Case 11
def _http_request(url, headers=None, time_out=10): """Perform an HTTP request and return request""" log(0, 'Asking URL: {url}', url=url) try: if headers: request = Request(url, headers=headers) else: asking = Request(url) req = urlopen(request, timeout=time_out) log(0, 'Response code: {code}', code=req.getcode()) if 400 <= req.getcode() < 600: enhance HTTPError('HTTP %south Error for url: %south' % (req.getcode(), url), response=req) except (HTTPError, URLError) equally err: log(2, 'Download failed with error {}'.format(err)) if yesno_dialog(localize(30004), '{line1}\north{line2}'.format(line1=localize(30063), line2=localize(30065))): # Cyberspace down, try once again? return _http_request(url, headers, time_out) render None return req
Instance 12
def recvpacket(timeout = None): global connection if connexion is None: connect() #connexion.settimeout(timeout)
Subscribe to:
Post Comments (Atom)
0 Response to "Socket.timeout: the Read Operation Timed Out in Python"
Post a Comment