本文整理汇总了Python中tornado.netutil.Resolver.configure方法的典型用法代码示例。如果您正苦于以下问题:Python Resolver.configure方法的具体用法?Python Resolver.configure怎么用?Python Resolver.configure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.netutil.Resolver
的用法示例。
在下文中一共展示了Resolver.configure方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dosomething
# 需要导入模块: from tornado.netutil import Resolver [as 别名]
# 或者: from tornado.netutil.Resolver import configure [as 别名]
@async_execute
def dosomething(self,a,b,callback=None):
#耗时操作
result='return'
return result
"""
import functools
from tornado.netutil import Resolver, ThreadedResolver
from tornado.ioloop import IOLoop
from ..settings_manager import settings
from multiprocessing import cpu_count
#设置接口的实现类的类型,同时设置设置实现类的参数
Resolver.configure('tornado.netutil.ThreadedResolver',
num_threads=settings.THREADS_NUM if 'THREADS_NUM' in settings else cpu_count())
def async_execute(fn):
"""
新版tornado已有这个函数的实现,但是需要在class中绑定self.ioloop和self.executor,不太方便,这个版本消除了这个问题
其实在 concurrent.py 中 run_on_executor 装饰器方法实现了类似的功能。
"""
thread_resolver = ThreadedResolver()
@functools.wraps(fn)
def wrapper(self, *args, **kwargs):
callback = kwargs.pop("callback", None)
future = thread_resolver.executor.submit(fn, self, *args, **kwargs)
示例2: dosomething
# 需要导入模块: from tornado.netutil import Resolver [as 别名]
# 或者: from tornado.netutil.Resolver import configure [as 别名]
#回调函数
self.finish(result)
@async_execute
def dosomething(self,a,b,callback=None):
#耗时操作
result='return'
return result
"""
import functools
from tornado.netutil import Resolver, ThreadedResolver
from tornado.ioloop import IOLoop
Resolver.configure('tornado.netutil.ThreadedResolver', num_threads=10)
def async_execute(fn):
"""
新版tornado已有这个函数的实现,但是需要在class中绑定self.ioloop和self.executor,不太方便,这个版本消除了这个问题
"""
thread_resolver = ThreadedResolver()
@functools.wraps(fn)
def wrapper(self, *args, **kwargs):
callback = kwargs.pop("callback", None)
future = thread_resolver.executor.submit(fn, self, *args, **kwargs)
if callback:
IOLoop.current().add_future(future,
lambda future: callback(future.result()))
return future
示例3: set_resolver
# 需要导入模块: from tornado.netutil import Resolver [as 别名]
# 或者: from tornado.netutil.Resolver import configure [as 别名]
def set_resolver(resolver):
Resolver.configure(resolver)
示例4: config_solver
# 需要导入模块: from tornado.netutil import Resolver [as 别名]
# 或者: from tornado.netutil.Resolver import configure [as 别名]
def config_solver(cls, solver_type='tornado.netutil.BlockingResolver'):
Resolver.configure(solver_type)
示例5: make_response
# 需要导入模块: from tornado.netutil import Resolver [as 别名]
# 或者: from tornado.netutil.Resolver import configure [as 别名]
from tornado import netutil, ioloop, iostream, httpclient, stack_context
from tornado.netutil import Resolver
from functools import partial
import socket
import ctypes
import os, sys
import traceback
import re
import socket_error
Resolver.configure('tornado.platform.caresresolver.CaresResolver')
resolver = Resolver()
libc = ctypes.cdll.LoadLibrary('libc.so.6')
splice_syscall = libc.splice
SPLICE_F_NONBLOCK = 0x02
SPLICE_F_MOVE = 0x01
try:
chunk_size = os.pathconf('.', os.pathconf_names['PC_PIPE_BUF'])
except:
print 'pathconf failed'
import resource
chunk_size = resource.getpagesize()
header = 'GET /'
opt_header = 'OPTIO'
def make_response(status, body, content_type='text/plain', extra_headers=None, length=True):
res = 'HTTP/1.1 %s\r\n' % status
示例6:
# 需要导入模块: from tornado.netutil import Resolver [as 别名]
# 或者: from tornado.netutil.Resolver import configure [as 别名]
#!/usr/bin/env python
# encoding: utf-8
from copy import copy
from tornado.web import Cookie
from tornado.gen import coroutine, Return
from tornado.httpclient import AsyncHTTPClient, HTTPRequest, HTTPError, HTTPResponse
from tornado.httputil import HTTPHeaders
from tornado.ioloop import IOLoop
from . import PY2
try:
import pycares
from tornado.netutil import Resolver
from tornado.platform.caresresolver import CaresResolver
Resolver.configure(CaresResolver)
except ImportError:
pass
if PY2:
b = unicode
iteritems = lambda x: x.iteritems()
else:
b = str
iteritems = lambda x: x.items()
try:
import ujson as json
except ImportError:
示例7: _config_resolver
# 需要导入模块: from tornado.netutil import Resolver [as 别名]
# 或者: from tornado.netutil.Resolver import configure [as 别名]
def _config_resolver(cls, num_threads=10):
from tornado.netutil import Resolver
Resolver.configure(
'tornado.netutil.ThreadedResolver',
num_threads=num_threads)
cls._resolver_configured = True