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


Python Timer.time方法代码示例

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


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

示例1: do_POST

# 需要导入模块: from util import Timer [as 别名]
# 或者: from util.Timer import time [as 别名]
    def do_POST(self):
        t = Timer()
        t.start()
        response = 200
        result = {}
        try:
            content_length = int(self.headers.getheader('content-length'))
            req = json.loads(self.rfile.read(content_length))
            print req

            req_type = req['type']
            result = None
            if req_type == 'catalog':
                result = json.dumps(self.server.catalog)
            elif req_type == 'execute':
                task = req['args']['task']
                json.dumps(BasicExecutor(self.server.cache, task).execute())
            elif req_type == 'lookup':
                uuid = req['args']['uuid']
                result = self.server.cache[uuid]
                if type(result) is pd.DataFrame:
                    page_size = int(req['args']['page_size'])
                    page_num = int(req['args']['page_num'])
                    i = page_size * page_num
                    j = i + page_size
                    result = result[i:j]
                result = result.to_json()
        except:
            print traceback.format_exc()
            response = 500
            result = '{}'
        t.stop()

        self.send_response(response)
        self.send_header('Content-type','application/json')
        self.end_headers()
        self.wfile.write(result)

        print 'Run Time:', t.time()
开发者ID:twareproj,项目名称:tware,代码行数:41,代码来源:server.py

示例2: Executor

# 需要导入模块: from util import Timer [as 别名]
# 或者: from util.Timer import time [as 别名]
class Executor(Process):
    def __init__(self, catalog, results, task):
        Process.__init__(self)
        self.catalog = catalog
        self.results = results
        self.task = task
        self.timer = Timer()

    def get_result(self, uuid):
        result = self.results[uuid]
        while result.complete == 0.0:
            time.sleep(0.0005)
            result = self.results[uuid]
        return result

    def wait(self, uuid):
        while self.results[uuid].complete == 0.0:
            time.sleep(0.0005)

    def run(self):
        self.timer.start()
        try:
            if isinstance(self.task, ClassifyTask):
                self.classify()
            elif isinstance(self.task, CorrelateTask):
                self.correlate()
            elif isinstance(self.task, DifferenceTask):
                self.difference()
            elif isinstance(self.task, FeatureSelectTask):
                self.feature_select()
            elif isinstance(self.task, FrequentItemsetsTask):
                self.frequent_itemsets()
            elif isinstance(self.task, IntersectTask):
                self.intersect()
            elif isinstance(self.task, LoadTask):
                self.load()
            elif isinstance(self.task, MergeTask):
                self.merge()
            elif isinstance(self.task, ProjectTask):
                self.project()
            elif isinstance(self.task, SelectTask):
                self.select()
            elif isinstance(self.task, UnionTask):
                self.union()
            else:
                raise NotImplementedError()
        except Exception as e:
            print str(e)
            result = ErrorResult(self.task, str(e))
            self.results[self.task.uuid] = result
        self.timer.stop()
        print 'task' + str(self.task.uuid) + ': ' + str(self.timer.time()) + 's'

    def classify(self):
        raise NotImplementedError()

    def correlate(self):
        raise NotImplementedError()

    def difference(self):
        raise NotImplementedError()

    def feature_select(self):
        raise NotImplementedError()

    def frequent_itemsets(self):
        raise NotImplementedError()

    def intersect(self):
        raise NotImplementedError()

    def load(self):
        raise NotImplementedError()

    def merge(self):
        raise NotImplementedError()

    def project(self):
        raise NotImplementedError()

    def select(self):
        raise NotImplementedError()

    def union(self):
        raise NotImplementedError()
开发者ID:twareproj,项目名称:tware,代码行数:87,代码来源:executor.py


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