当前位置: 首页>>代码示例>>Python>>正文


Python FuturesSession.trust_env方法代码示例

本文整理汇总了Python中requests_futures.sessions.FuturesSession.trust_env方法的典型用法代码示例。如果您正苦于以下问题:Python FuturesSession.trust_env方法的具体用法?Python FuturesSession.trust_env怎么用?Python FuturesSession.trust_env使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在requests_futures.sessions.FuturesSession的用法示例。


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

示例1: postLogs

# 需要导入模块: from requests_futures.sessions import FuturesSession [as 别名]
# 或者: from requests_futures.sessions.FuturesSession import trust_env [as 别名]
def postLogs(logcache):
    #post logs asynchronously with requests workers and check on the results
    #expects a queue object from the multiprocessing library
    #setting this within the processs to allow requests to establish a keep alive session with async workers.
    httpsession = FuturesSession(max_workers=2)
    httpsession.trust_env=False #turns off needless and repetitive .netrc check for creds
    canQuit=False
    logger.info('started posting process')
    def backgroundcallback(session, response):
        #release the connection back to the pool
        try: 
            r=response.result()
            response.close()
        except Exception as e:
            logger.error('Exception while posting message: %r'%e)

    while True:
        try:
            #see if we have anything to post
            #waiting a bit to not end until we are told we can stop.
            postdata=logcache.get(False,30)
            if postdata is None:
                #signalled from parent process that it's ok to stop.
                logcache.task_done()
                canQuit=True
                
            elif len(postdata)>0:
                url=random.choice(options.urls)
                r=httpsession.post(url,data=postdata,stream=False)
                logcache.task_done()
        except Empty as e:
            if canQuit:
                logger.info('signaling shutdown for threadpool executor')
                httpsession.executor.shutdown(wait=True)
                break

    logger.info('{0} done'.format('log posting task'))
开发者ID:DjDarthyGamer,项目名称:MozDef,代码行数:39,代码来源:cefTail2Mozdef.py

示例2: FuturesSession

# 需要导入模块: from requests_futures.sessions import FuturesSession [as 别名]
# 或者: from requests_futures.sessions.FuturesSession import trust_env [as 别名]
import json
import socket
import json
from optparse import OptionParser
from requests_futures.sessions import FuturesSession
from multiprocessing import Process, Queue
import random
import logging
from logging.handlers import SysLogHandler
from Queue import Empty
from requests.packages.urllib3.exceptions import ClosedPoolError
import requests
import time

httpsession = FuturesSession(max_workers=5)
httpsession.trust_env = False  # turns of needless .netrc check for creds
# a = requests.adapters.HTTPAdapter(max_retries=2)
# httpsession.mount('http://', a)


logger = logging.getLogger(sys.argv[0])
logger.level = logging.DEBUG

formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")


def postLogs(logcache):
    # post logs asynchronously with requests workers and check on the results
    # expects a queue object from the multiprocessing library
    posts = []
    try:
开发者ID:2xyo,项目名称:MozDef,代码行数:33,代码来源:json2Mozdef.py


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