• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pycurl.global_cleanup函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pycurl.global_cleanup函数的典型用法代码示例。如果您正苦于以下问题:Python global_cleanup函数的具体用法?Python global_cleanup怎么用?Python global_cleanup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了global_cleanup函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_global_init_ack_eintr

 def test_global_init_ack_eintr(self):
     # the GLOBAL_ACK_EINTR flag was introduced in libcurl-7.30, but can also
     # be backported for older versions of libcurl at the distribution level
     if not util.pycurl_version_less_than(7, 30) or hasattr(pycurl, 'GLOBAL_ACK_EINTR'):
         # initialize libcurl with the GLOBAL_ACK_EINTR flag
         pycurl.global_init(pycurl.GLOBAL_ACK_EINTR)
         pycurl.global_cleanup()
开发者ID:tempbottle,项目名称:pycurl,代码行数:7,代码来源:global_init_test.py


示例2: main

def main():
        global saw_error

        pycurl.global_init(pycurl.GLOBAL_DEFAULT)

        outf = file("/dev/null", "rb+")
        cm = pycurl.CurlMulti()

        # Set multi handle's options
        cm.setopt(pycurl.M_PIPELINING, 1)

        eh = pycurl.Curl()

        for x in range(1, 20):

                eh.setopt(pycurl.WRITEDATA, outf)
                eh.setopt(pycurl.URL, sys.argv[1])
                cm.add_handle(eh)

                while 1:
                        ret, active_handles = cm.perform()
                        if ret != pycurl.E_CALL_MULTI_PERFORM:
                                break

                while active_handles:
                        ret = cm.select(1.0)
                        if ret == -1:
                                continue
                        while 1:
                                ret, active_handles = cm.perform()
                                if ret != pycurl.E_CALL_MULTI_PERFORM:
                                        break

                count, good, bad = cm.info_read()

                for h, en, em in bad:
                        print "Transfer to %s failed with %d, %s\n" % \
                            (h.getinfo(pycurl.EFFECTIVE_URL), en, em)
                        raise RuntimeError

                for h in good:
                        httpcode = h.getinfo(pycurl.RESPONSE_CODE)
                        if httpcode != 200:
                                print "Transfer to %s failed with code %d\n" %\
                                    (h.getinfo(pycurl.EFFECTIVE_URL), httpcode)
                                raise RuntimeError

                        else:
                                print "Recd %d bytes from %s" % \
                                    (h.getinfo(pycurl.SIZE_DOWNLOAD),
                                    h.getinfo(pycurl.EFFECTIVE_URL))

                cm.remove_handle(eh)
                eh.reset()

        eh.close()
        cm.close()
        outf.close()

        pycurl.global_cleanup()
开发者ID:CongLi,项目名称:autotest-client-tests,代码行数:60,代码来源:test_reset.py


示例3: Shutdown

def Shutdown():
  """Stops the module-global HTTP client manager.

  Must be called before quitting the program and while exactly one thread is
  running.

  """
  pycurl.global_cleanup()
开发者ID:ekohl,项目名称:ganeti,代码行数:8,代码来源:rpc.py


示例4: cleanPycurl

 def cleanPycurl(self):
     """ make a global curl cleanup (currently unused) """
     if self.processingIds():
         return False
     pycurl.global_cleanup()
     pycurl.global_init(pycurl.GLOBAL_DEFAULT)
     self.downloaded = 0
     self.log.debug("Cleaned up pycurl")
     return True
开发者ID:beefone,项目名称:pyload,代码行数:9,代码来源:ThreadManager.py


示例5: test_global_init_ack_eintr

 def test_global_init_ack_eintr(self):
     # the GLOBAL_ACK_EINTR flag was introduced in libcurl-7.30, but can also
     # be backported for older versions of libcurl at the distribution level
     if util.pycurl_version_less_than(7, 30) and not hasattr(pycurl, 'GLOBAL_ACK_EINTR'):
         raise nose.plugins.skip.SkipTest('libcurl < 7.30.0 or no GLOBAL_ACK_EINTR')
     
     # initialize libcurl with the GLOBAL_ACK_EINTR flag
     pycurl.global_init(pycurl.GLOBAL_ACK_EINTR)
     pycurl.global_cleanup()
开发者ID:AdamJacobMuller,项目名称:pycurl,代码行数:9,代码来源:global_init_test.py


示例6: wrapper

  def wrapper(*args, **kwargs):
    # curl_global_init(3) and curl_global_cleanup(3) must be called with only
    # one thread running. This check is just a safety measure -- it doesn't
    # cover all cases.
    assert threading.activeCount() == 1, \
           "Found active threads when initializing pycURL"

    pycurl.global_init(pycurl.GLOBAL_ALL)
    try:
      return fn(*args, **kwargs)
    finally:
      pycurl.global_cleanup()
开发者ID:ekohl,项目名称:ganeti,代码行数:12,代码来源:client.py


示例7: perform

 def perform(self):
     print self.version()   
     filesize = self.get_filesize()
     pycurl.global_init(pycurl.GLOBAL_ALL) # GLOBAL_ALL must be set in normal
     
     if filesize == -1: # length not known, use single connection instead
         c = self.gen_curl()
         outfile = self.try_soutfile(self.filename)
         c.setopt(pycurl.WRITEFUNCTION, outfile.write)
         c.perform()
         outfile.close()
     else:
         curlpool = []
         blocksize = filesize / self.num_blocks + 1
         print filesize
         for p_start, p_end in [(x, x + blocksize) for x in xrange(0, filesize, blocksize)]:
             curlpool.append(self.gen_curl(p_start, p_end, filesize))
         m = pycurl.CurlMulti()
         m.handles = []
         for c in curlpool:
             m.add_handle(c)
             m.handles.append(c)
         try:
             while True:
                 ret, num_handles = m.perform()
                 if ret != pycurl.E_CALL_MULTI_PERFORM:
                     break
             while num_handles:
                 ret = m.select(1.0)
                 if ret == -1:
                     continue
                 
                 while True:
                     ret, num_handles = m.perform()
                     if ret != pycurl.E_CALL_MULTI_PERFORM:
                         break
             self.end_perform(normal = True)
             self.event.set()
         except KeyboardInterrupt:
             self.end_perform(normal = False)
         except SystemExit:
             self.end_perform(normal = False)
             
     pycurl.global_cleanup()
开发者ID:akashacn,项目名称:Tget,代码行数:44,代码来源:GetService.py


示例8: get_filesize

 def get_filesize(self):
     if hasattr(self, 'filesize') and self.filesize != None:
         return self.filesize
     
     pycurl.global_init(pycurl.GLOBAL_ALL) # GLOBAL_ALL must be set in normal
     curl = pycurl.Curl()
     curl.setopt(pycurl.HEADER, True)
     curl.setopt(pycurl.NOBODY, True)
     curl.setopt(pycurl.URL, self.url)
     curl.setopt(pycurl.TIMEOUT, HEADER_TIMEOUT)
     
     b = StringIO.StringIO()
     curl.setopt(pycurl.WRITEFUNCTION, b.write)
     curl.perform()
     try:
         size = int(re.findall("Content-Length: (\d+)", b.getvalue())[0])
     except:
         size = -1
     
     pycurl.global_cleanup()
     
     self.filesize = size
     return size
开发者ID:akashacn,项目名称:Tget,代码行数:23,代码来源:GetService.py


示例9: test_global_init_default

 def test_global_init_default(self):
     # initialize libcurl with DEFAULT flags
     pycurl.global_init(pycurl.GLOBAL_DEFAULT)
     pycurl.global_cleanup()
开发者ID:AdamJacobMuller,项目名称:pycurl,代码行数:4,代码来源:global_init_test.py


示例10: main


#.........这里部分代码省略.........
	parser = OptionParser(usage=usage)
	
	#	parser.add_option('-q', '--quiet', action="store_const", const=0, dest="v", default=1, help='quiet')
	
	parser.add_option('-c', '--config', action='store', dest='config', default=DEFAULT_CONF, help='load parameters from configfile (default: ' + DEFAULT_CONF + ')')
	
	parser.add_option('-t', '--tcp', action='store_const', dest='mode', const='tcp', help='tcp mode (default)')
	
	parser.add_option('-u', '--udp', action='store_const', dest='mode', const='udp', help='udp mode')
	
	parser.add_option('-L', action='append', dest='forward', help='forward port:remotehost:remoteport (like ssh)')
		
	parser.add_option('--url', action="store", dest="url", help='URL of tunnelendpoint')
	
	parser.add_option('--proxy', action='store', dest='proxy', help='proxy to use')
	
	parser.add_option('--auth', action='store', dest='auth', help='auth with user:password')
	
	parser.add_option('-a', '--agent', action='store', dest='agent', help='fake useragent')
	
	parser.add_option('-v', '--verbose', action='store_const', dest='verbose', const=1, help='verbose')
	
	
	parser.add_option('--no-verify-ssl', action='store_true', dest='nv', help='do not verify ssl-host')
	parser.add_option('--verify-ssl', action='store_false', dest='nv', help='do not verify ssl-host')
	
	global options
	(options, args) = parser.parse_args()
		
	cparser = ConfigParser.ConfigParser(defaults={
		'mode': 'tcp',
		'url': DEFAULT_URL,
		'auth': '',
		'proxy': '',
		'agent': '',
		'verbose': 0,
		'verify': True
		})

	cparser.read(options.config)
	
	if cparser.has_section('pyhstopc'):
		if not options.url:	options.url = cparser.get('pyhstopc', 'url')
		if not options.auth:	options.auth = cparser.get('pyhstopc', 'auth')
		if not options.agent:	options.agent = cparser.get('pyhstopc', 'agent')
		if not options.proxy:	options.proxy = cparser.get('pyhstopc', 'proxy')
		if not options.forward:
			options.forward = []
			try:
				options.forward.extend(cparser.get('pyhstopc', 'forward').split(','))
			except ConfigParser.NoOptionError:
				pass
		try:
			if not options.verbose:	options.verbose = cparser.getint('pyhstopc', 'verbose')
		except TypeError:
			options.verbose = 0
		try:
			if options.nv == None:	options.nv = not cparser.getboolean('pyhstopc', 'verify')
		except TypeError:
			options.nv = False
	
	cparser = None
	
	tmpforward = options.forward
	options.forward = []
	for i in tmpforward:
		try:
			lport, rhost, rport = i.split(':')
			options.forward.append((int(lport.strip()), rhost.strip(), int(rport.strip()),'tcp'))
		except (KeyError, ValueError):
			try:
				lport, rhost, rport, mode = i.split(':')
				options.forward.append((int(lport.strip()), rhost.strip(), int(rport.strip()), mode))
			except (KeyError, ValueError):
				print 'malformed forward option: ', i
	
	print 'pyhstopc Version: ' + VERSION
	print 'terminate with EOF'

	print 'start..'
	
	pycurl.global_init(pycurl.GLOBAL_ALL)
	
	sls = []
	for i in range(len(options.forward)):
		sl = socketListener(i)
		sl.listen()
		
	try:
		input = sys.stdin.readline()
		while input:
			input = sys.stdin.readline()
	except KeyboardInterrupt:
		print 'interrupted'
	
	for sl in sls:
		sl.terminate()
	
	pycurl.global_cleanup()
	print 'end..'
开发者ID:BackupTheBerlios,项目名称:hstop-svn,代码行数:101,代码来源:pyhstopc.py


示例11: cleanup

 def cleanup(self):
     """do global cleanup, should be called when finished with pycurl"""
     pycurl.global_cleanup()
开发者ID:beefone,项目名称:pyload,代码行数:3,代码来源:ThreadManager.py


示例12: main

def main():
	usage = "usage: %prog [options]"
	parser = OptionParser(usage=usage)
	
	#	parser.add_option('-q', '--quiet', action="store_const", const=0, dest="v", default=1, help='quiet')
	#	parser.add_option('-v', '--verbose', action="store_const", const=1, dest="v", help='verbose')
	
	parser.add_option('-c', '--config', action='store', dest='config', default=DEFAULT_CONF, help='load parameters from configfile (default: ' + DEFAULT_CONF + ')')
	
	parser.add_option('-t', '--tcp', action='store_const', dest='mode', const='tcp', help='tcp mode (default)')
	
	#parser.add_option('-u', '--udp', action='store_const', dest='t', const='udp', help='udp mode')
		
	parser.add_option('-p', '--port', action="store", type='int', dest="port", help='port to listen (default: '+ str(DEFAULT_LISTENPORT) +')')
	
	parser.add_option('--url', action="store", dest="url", help='URL of tunnelendpoint (default: '+ DEFAULT_URL +')')
	
	parser.add_option('-d', '--dest', action="store", dest="dest", help='destination to connect to (default ' + DEFAULT_TARGET + ')')
	
	parser.add_option('--proxy', action='store', dest='proxy', help='proxy to use')
	
	parser.add_option('--auth', action='store', dest='auth', help='auth with user:password')
	
	parser.add_option('-v', '--verbose', action='store_const', dest='verbose', const=1, help='verbose')
	
	
	#parser.add_option('--no-proxy', action='store_true', dest='np', default=False, help='use no proxy (default: use proxy from env)')
	
	global options
	(options, args) = parser.parse_args()
	
	cparser = ConfigParser.ConfigParser(defaults={
		'mode': 'tcp',
		'port': DEFAULT_LISTENPORT,
		'url': DEFAULT_URL,
		'dest': DEFAULT_TARGET,
		'auth': '',
		'proxy': '',
		'verbose': 0
		})

	cparser.read(options.config)
	
	if cparser.has_section('pyhstopc'):
		if not options.mode:	options.mode = cparser.get('pyhstopc', 'mode')
		if not options.port:	options.port = cparser.getint('pyhstopc', 'port')
		if not options.url:	options.url = cparser.get('pyhstopc', 'url')
		if not options.dest:	options.dest = cparser.get('pyhstopc', 'dest')
		if not options.auth:	options.auth = cparser.get('pyhstopc', 'auth')
		if not options.proxy:	options.proxy = cparser.get('pyhstopc', 'proxy')
		try:
			if not options.verbose:	options.verbose = cparser.getint('pyhstopc', 'verbose')
		except TypeError:
			options.verbose = 0
	
	cparser = None
		
	print 'pyhstopc Version: ' + VERSION
	print 'terminate with EOF'

	print 'start..'
	
	if USE_CURL:
		pycurl.global_init(pycurl.GLOBAL_ALL)
	
	sl = socketListener()
	sl.listen()
		
	input = sys.stdin.readline()
	while input:
		input = sys.stdin.readline()
		
	sl.terminate()
	if USE_CURL:
		pycurl.global_cleanup()
	print 'end..'
开发者ID:BackupTheBerlios,项目名称:hstop-svn,代码行数:76,代码来源:pyhstopc.py


示例13: process

    def process(self, args):
        # Perform any base class processing.
        if not super(JsonProcess, self).process(args):
            return

        # Check to see if the JSON file exists.
        if args.json == "-":
            json = {}
        elif os.path.isfile(args.json):
            self.log.info("Using JSON file: " + args.json)
            stream = open(args.json, 'r')
            json = simplejson.load(stream)
            stream.close()
        else:
            self.log.info("Creating JSON file: " + args.json)
            json = {}

        # If the file exists and we have the enable flag, then we
        # check to see if we are going to force writing the file.
        if "enable-tmdb" in json and not args.force:
            self.log.info("Information already cached, skipping")
            return False

        # If the ID is 0 or less, then we disable it.
        if args.id <= 0:
            # Remove any existing JSON data and disable TMDB.
            json["enable-tmdb"] = False

            if "tmdb" in json:
                del json["tmdb"]
        else:
            # Set up the configuration for TMDB.
            self.configure()

            url = "http://api.themoviedb.org/3/movie/{0}?api_key={1}".format(
                args.id,
                args.api_key)
            tmdb_json = self.get_json(url)

            # Insert the TMDB JSON data into the JSON.
            json["enable-tmdb"] = True
            json["tmdb"] = tmdb_json
        
        # Now that we are done, get the formatted JSON file.
        formatted = simplejson.dumps(json, indent=4, sort_keys=True)

        # Figure out how to output the file.
        if not args.output:
            args.output = args.json

        if args.output == "-":
            # Just print it to the output.
            print formatted
        else:
            # Open the stream for writing.
            stream = open(args.output, "w")
            simplejson.dump(json, stream, sort_keys=True, indent=4)
            stream.close()

        # Finish up the PyCurl library.
        pycurl.global_cleanup()
开发者ID:dmoonfire,项目名称:mfgames-media-python,代码行数:61,代码来源:themoviedb.py


示例14: cleanup_libcurl

def cleanup_libcurl():
    pycurl.global_cleanup()
开发者ID:adarshr,项目名称:miro,代码行数:2,代码来源:httpclient.py


示例15: an

    try:
        print 'get_data: fetch %s', url
        curl.perform()
    except pycurl.error, e:

        # pycurl.error is an (errorcode, errormsg) tuple

        print 'cURL command failed! %s', e[1]
        return ''

    http_status = curl.getinfo(pycurl.HTTP_CODE)

    # Clean up after cURL

    curl.close()
    pycurl.global_cleanup()

    server_status = ''

    if http_status == http_success:

        # Go to start of buffer

        output.seek(0)
        try:
            server_status = output.readlines()
        except:
            print 'Failed to parse server status'
            return None
    else:
        print 'Server returned HTTP code %d, expected %d', http_status, \
开发者ID:heromod,项目名称:migrid,代码行数:31,代码来源:curlexample.py


示例16: __del__

 def __del__(self):
     pycurl.global_cleanup()
开发者ID:developerror,项目名称:webdavclient,代码行数:2,代码来源:client.py


示例17: __init__

 def __init__(self, pool, cr):
     super(taobao_shop, self).__init__(pool, cr)
     #pycurl两个函数不是线程安全。所以在主线程中进行一次的初始化和清除
     import pycurl
     pycurl.global_init(pycurl.GLOBAL_DEFAULT)
     pycurl.global_cleanup()
开发者ID:BGEray,项目名称:openerp-taobao,代码行数:6,代码来源:taobao_shop.py


示例18: createContainer

    def createContainer(self, src=None, target_info=None, arches=None,
                        scratch=None, isolated=None, yum_repourls=[],
                        branch=None, push_url=None, koji_parent_build=None,
                        release=None):
        if not yum_repourls:
            yum_repourls = []

        this_task = self.session.getTaskInfo(self.id)
        self.logger.debug("This task: %r", this_task)
        owner_info = self.session.getUser(this_task['owner'])
        self.logger.debug("Started by %s", owner_info['name'])

        scm = My_SCM(src)
        scm.assert_allowed(self.options.allowed_scms)
        git_uri = scm.get_git_uri()
        component = scm.get_component()
        arch = None

        if not arches:
            raise ContainerError("arches aren't specified")

        create_build_args = {
            'git_uri': git_uri,
            'git_ref': scm.revision,
            'user': owner_info['name'],
            'component': component,
            'target': target_info['name'],
            'yum_repourls': yum_repourls,
            'scratch': scratch,
            'koji_task_id': self.id,
            'architecture': arch
        }
        if branch:
            create_build_args['git_branch'] = branch
        if push_url:
            create_build_args['git_push_url'] = push_url

        try:
            orchestrator_create_build_args = create_build_args.copy()
            orchestrator_create_build_args['platforms'] = arches
            if koji_parent_build:
                orchestrator_create_build_args['koji_parent_build'] = koji_parent_build
            if isolated:
                orchestrator_create_build_args['isolated'] = isolated
            if release:
                orchestrator_create_build_args['release'] = release

            create_method = self.osbs().create_orchestrator_build
            self.logger.debug("Starting %s with params: '%s",
                              create_method, orchestrator_create_build_args)
            build_response = create_method(**orchestrator_create_build_args)
        except (AttributeError, OsbsOrchestratorNotEnabled):
            # Older osbs-client, or else orchestration not enabled
            create_build_args['architecture'] = arch = arches[0]
            create_method = self.osbs().create_build
            self.logger.debug("Starting %s with params: '%s'",
                              create_method, create_build_args)
            build_response = create_method(**create_build_args)

        build_id = build_response.get_build_name()
        self.logger.debug("OSBS build id: %r", build_id)

        # When builds are cancelled the builder plugin process gets SIGINT and SIGKILL
        # If osbs has started a build it should get cancelled
        def sigint_handler(*args, **kwargs):
            if not build_id:
                return

            self.logger.warn("Cannot read logs, cancelling build %s", build_id)
            self.osbs().cancel_build(build_id)

        signal.signal(signal.SIGINT, sigint_handler)

        self.logger.debug("Waiting for osbs build_id: %s to be scheduled.",
                          build_id)
        # we need to wait for kubelet to schedule the build, otherwise it's 500
        self.osbs().wait_for_build_to_get_scheduled(build_id)
        self.logger.debug("Build was scheduled")

        osbs_logs_dir = self.resultdir()
        koji.ensuredir(osbs_logs_dir)
        pid = os.fork()
        if pid:
            try:
                self._incremental_upload_logs(pid)
            except koji.ActionNotAllowed:
                pass
        else:
            full_output_name = os.path.join(osbs_logs_dir,
                                            'openshift-incremental.log')

            # Make sure curl is initialized again otherwise connections via SSL
            # fails with NSS error -8023 and curl_multi.info_read()
            # returns error code 35 (SSL CONNECT failed).
            # See http://permalink.gmane.org/gmane.comp.web.curl.library/38759
            self._osbs = None
            self.logger.debug("Running pycurl global cleanup")
            pycurl.global_cleanup()

            # Following retry code is here mainly to workaround bug which causes
#.........这里部分代码省略.........
开发者ID:maxamillion,项目名称:koji-containerbuild,代码行数:101,代码来源:builder_containerbuild.py



注:本文中的pycurl.global_cleanup函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pycurl.global_init函数代码示例发布时间:2022-05-25
下一篇:
Python tools.dtype_to_ctype函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap