Python pycurl.E_CALL_MULTI_PERFORM Examples
The following are 23
code examples of pycurl.E_CALL_MULTI_PERFORM().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pycurl
, or try the search function
.
Example #1
Source File: curl_httpclient.py From tornado-zh with MIT License | 6 votes |
def _handle_events(self, fd, events): """Called by IOLoop when there is activity on one of our file descriptors. """ action = 0 if events & ioloop.IOLoop.READ: action |= pycurl.CSELECT_IN if events & ioloop.IOLoop.WRITE: action |= pycurl.CSELECT_OUT while True: try: ret, num_handles = self._multi.socket_action(fd, action) except pycurl.error as e: ret = e.args[0] if ret != pycurl.E_CALL_MULTI_PERFORM: break self._finish_pending_requests()
Example #2
Source File: curl_httpclient.py From tornado-zh with MIT License | 6 votes |
def _handle_events(self, fd, events): """Called by IOLoop when there is activity on one of our file descriptors. """ action = 0 if events & ioloop.IOLoop.READ: action |= pycurl.CSELECT_IN if events & ioloop.IOLoop.WRITE: action |= pycurl.CSELECT_OUT while True: try: ret, num_handles = self._multi.socket_action(fd, action) except pycurl.error as e: ret = e.args[0] if ret != pycurl.E_CALL_MULTI_PERFORM: break self._finish_pending_requests()
Example #3
Source File: curl_httpclient.py From EventGhost with GNU General Public License v2.0 | 6 votes |
def _handle_events(self, fd, events): """Called by IOLoop when there is activity on one of our file descriptors. """ action = 0 if events & ioloop.IOLoop.READ: action |= pycurl.CSELECT_IN if events & ioloop.IOLoop.WRITE: action |= pycurl.CSELECT_OUT while True: try: ret, num_handles = self._multi.socket_action(fd, action) except pycurl.error as e: ret = e.args[0] if ret != pycurl.E_CALL_MULTI_PERFORM: break self._finish_pending_requests()
Example #4
Source File: curl_httpclient.py From viewfinder with Apache License 2.0 | 6 votes |
def _handle_events(self, fd, events): """Called by IOLoop when there is activity on one of our file descriptors. """ action = 0 if events & ioloop.IOLoop.READ: action |= pycurl.CSELECT_IN if events & ioloop.IOLoop.WRITE: action |= pycurl.CSELECT_OUT while True: try: ret, num_handles = self._socket_action(fd, action) except pycurl.error as e: ret = e.args[0] if ret != pycurl.E_CALL_MULTI_PERFORM: break self._finish_pending_requests()
Example #5
Source File: curl_httpclient.py From viewfinder with Apache License 2.0 | 6 votes |
def _handle_events(self, fd, events): """Called by IOLoop when there is activity on one of our file descriptors. """ action = 0 if events & ioloop.IOLoop.READ: action |= pycurl.CSELECT_IN if events & ioloop.IOLoop.WRITE: action |= pycurl.CSELECT_OUT while True: try: ret, num_handles = self._socket_action(fd, action) except pycurl.error as e: ret = e.args[0] if ret != pycurl.E_CALL_MULTI_PERFORM: break self._finish_pending_requests()
Example #6
Source File: curl_httpclient.py From honeything with GNU General Public License v3.0 | 6 votes |
def _handle_events(self, fd, events): """Called by IOLoop when there is activity on one of our file descriptors. """ action = 0 if events & ioloop.IOLoop.READ: action |= pycurl.CSELECT_IN if events & ioloop.IOLoop.WRITE: action |= pycurl.CSELECT_OUT while True: try: ret, num_handles = self._socket_action(fd, action) except pycurl.error, e: ret = e.args[0] if ret != pycurl.E_CALL_MULTI_PERFORM: break
Example #7
Source File: curl_httpclient.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def _handle_force_timeout(self): """Called by IOLoop periodically to ask libcurl to process any events it may have forgotten about. """ with stack_context.NullContext(): while True: try: ret, num_handles = self._multi.socket_all() except pycurl.error as e: ret = e.args[0] if ret != pycurl.E_CALL_MULTI_PERFORM: break self._finish_pending_requests()
Example #8
Source File: curl_httpclient.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def _handle_timeout(self): """Called by IOLoop when the requested timeout has passed.""" with stack_context.NullContext(): self._timeout = None while True: try: ret, num_handles = self._multi.socket_action( pycurl.SOCKET_TIMEOUT, 0) except pycurl.error as e: ret = e.args[0] if ret != pycurl.E_CALL_MULTI_PERFORM: break self._finish_pending_requests() # In theory, we shouldn't have to do this because curl will # call _set_timeout whenever the timeout changes. However, # sometimes after _handle_timeout we will need to reschedule # immediately even though nothing has changed from curl's # perspective. This is because when socket_action is # called with SOCKET_TIMEOUT, libcurl decides internally which # timeouts need to be processed by using a monotonic clock # (where available) while tornado uses python's time.time() # to decide when timeouts have occurred. When those clocks # disagree on elapsed time (as they will whenever there is an # NTP adjustment), tornado might call _handle_timeout before # libcurl is ready. After each timeout, resync the scheduled # timeout with libcurl's current state. new_timeout = self._multi.timeout() if new_timeout >= 0: self._set_timeout(new_timeout)
Example #9
Source File: dahua_event.py From home-assistant-dahua-event with MIT License | 5 votes |
def run(self): """Fetch events""" while 1: Ret, NumHandles = self.CurlMultiObj.perform() if Ret != pycurl.E_CALL_MULTI_PERFORM: break Ret = self.CurlMultiObj.select(1.0) while not self.stopped.isSet(): # Sleeps to ease load on processor time.sleep(.05) Ret, NumHandles = self.CurlMultiObj.perform() if NumHandles != self.NumCurlObjs: _, Success, Error = self.CurlMultiObj.info_read() for CurlObj in Success: DahuaDevice = next(filter(lambda x: x.CurlObj == CurlObj, self.Devices)) if DahuaDevice.Reconnect: continue DahuaDevice.OnDisconnect("Success") DahuaDevice.Reconnect = time.time() + 5 for CurlObj, ErrorNo, ErrorStr in Error: DahuaDevice = next(filter(lambda x: x.CurlObj == CurlObj, self.Devices)) if DahuaDevice.Reconnect: continue DahuaDevice.OnDisconnect("{0} ({1})".format(ErrorStr, ErrorNo)) DahuaDevice.Reconnect = time.time() + 5 for DahuaDevice in self.Devices: if DahuaDevice.Reconnect and DahuaDevice.Reconnect < time.time(): self.CurlMultiObj.remove_handle(DahuaDevice.CurlObj) self.CurlMultiObj.add_handle(DahuaDevice.CurlObj) DahuaDevice.Reconnect = None #if Ret != pycurl.E_CALL_MULTI_PERFORM: break
Example #10
Source File: myhttp.py From wfuzz with GNU General Public License v2.0 | 5 votes |
def _read_multi_stack(self): # Check for curl objects which have terminated, and add them to the curlh_freelist while not self.exit_job: while not self.exit_job: ret, num_handles = self.m.perform() if ret != pycurl.E_CALL_MULTI_PERFORM: break num_q, ok_list, err_list = self.m.info_read() for curl_h in ok_list: self._process_curl_handle(curl_h) self.m.remove_handle(curl_h) self.curlh_freelist.append(curl_h) for curl_h, errno, errmsg in err_list: buff_body, buff_header, res, poolid = curl_h.response_queue if not self._process_curl_should_retry(res, errno, poolid): self._process_curl_handle_error(res, errno, errmsg, poolid) self.m.remove_handle(curl_h) self.curlh_freelist.append(curl_h) while self.curlh_freelist and self._request_list: curl_h = self.curlh_freelist.pop() fuzzres, poolid = self._request_list.popleft() self.m.add_handle( self._prepare_curl_h(curl_h, fuzzres, poolid) ) self._stop_to_pools() # cleanup multi stack for c in self.handles: c.close() self.curlh_freelist.append(c) self.m.close()
Example #11
Source File: utils.py From marathon-lb with Apache License 2.0 | 5 votes |
def _perform_on_curl(self): while True: ret, num_handles = self.curlmulti.perform() if ret != pycurl.E_CALL_MULTI_PERFORM: break return num_handles
Example #12
Source File: httpclient.py From honeything with GNU General Public License v3.0 | 5 votes |
def _handle_timeout(self): """Called by IOLoop when the requested timeout has passed.""" self._timeout = None while True: try: ret, num_handles = self._multi.socket_action( pycurl.SOCKET_TIMEOUT, 0) except Exception, e: ret = e[0] if ret != pycurl.E_CALL_MULTI_PERFORM: break
Example #13
Source File: httpclient.py From honeything with GNU General Public License v3.0 | 5 votes |
def _handle_events(self, fd, events): """Called by IOLoop when there is activity on one of our file descriptors. """ action = 0 if events & ioloop.IOLoop.READ: action |= pycurl.CSELECT_IN if events & ioloop.IOLoop.WRITE: action |= pycurl.CSELECT_OUT while True: try: ret, num_handles = self._multi.socket_action(fd, action) except Exception, e: ret = e[0] if ret != pycurl.E_CALL_MULTI_PERFORM: break
Example #14
Source File: curl_httpclient.py From honeything with GNU General Public License v3.0 | 5 votes |
def _handle_force_timeout(self): """Called by IOLoop periodically to ask libcurl to process any events it may have forgotten about. """ with stack_context.NullContext(): while True: try: ret, num_handles = self._multi.socket_all() except pycurl.error, e: ret = e.args[0] if ret != pycurl.E_CALL_MULTI_PERFORM: break self._finish_pending_requests()
Example #15
Source File: curl_httpclient.py From honeything with GNU General Public License v3.0 | 5 votes |
def _handle_timeout(self): """Called by IOLoop when the requested timeout has passed.""" with stack_context.NullContext(): self._timeout = None while True: try: ret, num_handles = self._socket_action( pycurl.SOCKET_TIMEOUT, 0) except pycurl.error, e: ret = e.args[0] if ret != pycurl.E_CALL_MULTI_PERFORM: break self._finish_pending_requests() # In theory, we shouldn't have to do this because curl will # call _set_timeout whenever the timeout changes. However, # sometimes after _handle_timeout we will need to reschedule # immediately even though nothing has changed from curl's # perspective. This is because when socket_action is # called with SOCKET_TIMEOUT, libcurl decides internally which # timeouts need to be processed by using a monotonic clock # (where available) while tornado uses python's time.time() # to decide when timeouts have occurred. When those clocks # disagree on elapsed time (as they will whenever there is an # NTP adjustment), tornado might call _handle_timeout before # libcurl is ready. After each timeout, resync the scheduled # timeout with libcurl's current state.
Example #16
Source File: curl_httpclient.py From viewfinder with Apache License 2.0 | 5 votes |
def _handle_timeout(self): """Called by IOLoop when the requested timeout has passed.""" with stack_context.NullContext(): self._timeout = None while True: try: ret, num_handles = self._socket_action( pycurl.SOCKET_TIMEOUT, 0) except pycurl.error as e: ret = e.args[0] if ret != pycurl.E_CALL_MULTI_PERFORM: break self._finish_pending_requests() # In theory, we shouldn't have to do this because curl will # call _set_timeout whenever the timeout changes. However, # sometimes after _handle_timeout we will need to reschedule # immediately even though nothing has changed from curl's # perspective. This is because when socket_action is # called with SOCKET_TIMEOUT, libcurl decides internally which # timeouts need to be processed by using a monotonic clock # (where available) while tornado uses python's time.time() # to decide when timeouts have occurred. When those clocks # disagree on elapsed time (as they will whenever there is an # NTP adjustment), tornado might call _handle_timeout before # libcurl is ready. After each timeout, resync the scheduled # timeout with libcurl's current state. new_timeout = self._multi.timeout() if new_timeout >= 0: self._set_timeout(new_timeout)
Example #17
Source File: curl_httpclient.py From viewfinder with Apache License 2.0 | 5 votes |
def _handle_force_timeout(self): """Called by IOLoop periodically to ask libcurl to process any events it may have forgotten about. """ with stack_context.NullContext(): while True: try: ret, num_handles = self._multi.socket_all() except pycurl.error as e: ret = e.args[0] if ret != pycurl.E_CALL_MULTI_PERFORM: break self._finish_pending_requests()
Example #18
Source File: curl_httpclient.py From viewfinder with Apache License 2.0 | 5 votes |
def _handle_timeout(self): """Called by IOLoop when the requested timeout has passed.""" with stack_context.NullContext(): self._timeout = None while True: try: ret, num_handles = self._socket_action( pycurl.SOCKET_TIMEOUT, 0) except pycurl.error as e: ret = e.args[0] if ret != pycurl.E_CALL_MULTI_PERFORM: break self._finish_pending_requests() # In theory, we shouldn't have to do this because curl will # call _set_timeout whenever the timeout changes. However, # sometimes after _handle_timeout we will need to reschedule # immediately even though nothing has changed from curl's # perspective. This is because when socket_action is # called with SOCKET_TIMEOUT, libcurl decides internally which # timeouts need to be processed by using a monotonic clock # (where available) while tornado uses python's time.time() # to decide when timeouts have occurred. When those clocks # disagree on elapsed time (as they will whenever there is an # NTP adjustment), tornado might call _handle_timeout before # libcurl is ready. After each timeout, resync the scheduled # timeout with libcurl's current state. new_timeout = self._multi.timeout() if new_timeout >= 0: self._set_timeout(new_timeout)
Example #19
Source File: curl_httpclient.py From tornado-zh with MIT License | 5 votes |
def _handle_timeout(self): """Called by IOLoop when the requested timeout has passed.""" with stack_context.NullContext(): self._timeout = None while True: try: ret, num_handles = self._multi.socket_action( pycurl.SOCKET_TIMEOUT, 0) except pycurl.error as e: ret = e.args[0] if ret != pycurl.E_CALL_MULTI_PERFORM: break self._finish_pending_requests() # In theory, we shouldn't have to do this because curl will # call _set_timeout whenever the timeout changes. However, # sometimes after _handle_timeout we will need to reschedule # immediately even though nothing has changed from curl's # perspective. This is because when socket_action is # called with SOCKET_TIMEOUT, libcurl decides internally which # timeouts need to be processed by using a monotonic clock # (where available) while tornado uses python's time.time() # to decide when timeouts have occurred. When those clocks # disagree on elapsed time (as they will whenever there is an # NTP adjustment), tornado might call _handle_timeout before # libcurl is ready. After each timeout, resync the scheduled # timeout with libcurl's current state. new_timeout = self._multi.timeout() if new_timeout >= 0: self._set_timeout(new_timeout)
Example #20
Source File: curl_httpclient.py From tornado-zh with MIT License | 5 votes |
def _handle_force_timeout(self): """Called by IOLoop periodically to ask libcurl to process any events it may have forgotten about. """ with stack_context.NullContext(): while True: try: ret, num_handles = self._multi.socket_all() except pycurl.error as e: ret = e.args[0] if ret != pycurl.E_CALL_MULTI_PERFORM: break self._finish_pending_requests()
Example #21
Source File: curl_httpclient.py From tornado-zh with MIT License | 5 votes |
def _handle_timeout(self): """Called by IOLoop when the requested timeout has passed.""" with stack_context.NullContext(): self._timeout = None while True: try: ret, num_handles = self._multi.socket_action( pycurl.SOCKET_TIMEOUT, 0) except pycurl.error as e: ret = e.args[0] if ret != pycurl.E_CALL_MULTI_PERFORM: break self._finish_pending_requests() # In theory, we shouldn't have to do this because curl will # call _set_timeout whenever the timeout changes. However, # sometimes after _handle_timeout we will need to reschedule # immediately even though nothing has changed from curl's # perspective. This is because when socket_action is # called with SOCKET_TIMEOUT, libcurl decides internally which # timeouts need to be processed by using a monotonic clock # (where available) while tornado uses python's time.time() # to decide when timeouts have occurred. When those clocks # disagree on elapsed time (as they will whenever there is an # NTP adjustment), tornado might call _handle_timeout before # libcurl is ready. After each timeout, resync the scheduled # timeout with libcurl's current state. new_timeout = self._multi.timeout() if new_timeout >= 0: self._set_timeout(new_timeout)
Example #22
Source File: client.py From pycopia with Apache License 2.0 | 4 votes |
def perform(self, logfile=None): """Fetch all of the added Request objects. Return two lists. The first list is a list of responses that completed. The second is list of the requests that errored. """ m = pycurl.CurlMulti() requests = [] num_q = num_urls = len(self._requests) reqs = self._requests self._requests = [] for req in reqs: c, resp = req.get_requester() c.resp = resp m.add_handle(c) requests.append(c) del reqs while 1: ret, num_handles = m.perform() if ret != pycurl.E_CALL_MULTI_PERFORM: break num_handles = num_urls while num_handles: ret = m.select(5.0) if ret == -1: continue while 1: ret, num_handles = m.perform() if ret != pycurl.E_CALL_MULTI_PERFORM: break goodlist = [] errlist = [] while 1: num_q, ok_list, err_list = m.info_read(num_urls) for c in ok_list: resp = c.resp del c.resp resp.error = None m.remove_handle(c) resp.finalize(c) goodlist.append(resp) for c, errno, errmsg in err_list: resp = c.resp del c.resp resp.error = (errno, errmsg) m.remove_handle(c) errlist.append(resp) if num_q == 0: break m.close() return goodlist, errlist
Example #23
Source File: curl_loop.py From falsy with MIT License | 4 votes |
def perform(cls): if cls._futures: while True: status, num_active = cls._multi.perform() if status != pycurl.E_CALL_MULTI_PERFORM: break while True: num_ready, success, fail = cls._multi.info_read() for c in success: cc = cls._futures.pop(c) result = curl_result(c) result['url'] = c._raw_url result['id'] = c._raw_id result['state'] = 'normal' result['spider'] = 'pycurl' result['payload'] = payload = c._raw_payload # post_func = payload.get('post_func') # if type(post_func) == str: # post_func = load(post_func) # if post_func: # result = post_func(payload, result) cc.set_result(result) for c, err_num, err_msg in fail: print('error:', err_num, err_msg, c.getinfo(pycurl.EFFECTIVE_URL)) result = curl_result(c) result['url'] = c._raw_url result['id'] = c._raw_id result['state'] = 'error' result['spider'] = 'pycurl' result['error_code'] = err_num result['error_desc'] = err_msg result['payload'] = payload = c._raw_payload # post_func = payload.get('post_func') # if type(post_func) == str: # post_func = load(post_func) # if post_func: # result2 = post_func(payload, result) # if type(result2) is dict and len(result2) >= len(result): # result = result2 cls._futures.pop(c).set_exception(CurlLoop.CurlException(code=err_num, desc=err_msg, data=result)) if num_ready == 0: break