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

Python timer.start函数代码示例

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

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



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

示例1: run_agent

    def run_agent(self, s, beta=0, iteration=1):
        timer.start("running agent")
        merged_pairs = []
        while not s.is_complete():
            example = s.get_example(self.training)
            n_candidates = example['starts'].size + 1

            if self.training:
                self.replay_memory.update(example)

            if random.random() > beta:
                if iteration == -1:
                    i = n_candidates - 1
                else:
                    timer.start("predict")
                    scores = self.model.predict_on_batch(example)[0]
                    if self.training:
                        self.loss_aggregator.update(np.sum(scores * example['costs']))
                    i = np.argmax(scores[:, 0])
                    timer.stop("predict")
            else:
                i = np.argmin(example['costs'][:, 0])
            if i != n_candidates - 1:
                merged_pairs.append((s.candidate_antecedents[i], s.current_mention))
            s.do_action(i)
        timer.stop("running agent")
        return merged_pairs
开发者ID:clarkkev,项目名称:deep-coref,代码行数:27,代码来源:clustering_learning.py


示例2: finish_workers

	def finish_workers( self ):
		timer.start('work.finish.workers')
		finished_worker_cnt = 0
		for k, worker in enumerate( self.workers ):
			if worker.process.poll() is not None:
				(stdout, stderr) = worker.process.communicate()
				print "Local execution complete (%s): %s (return code %d)" % (worker.call.cbid, worker.call.body['cmd'], worker.process.returncode)
				finished_worker_cnt += 1

				if worker.process.returncode != 0:
					if len(stdout)>0:
						d( 'exec', 'stdout:\n', stdout )
					if len(stderr)>0:
						d( 'exec', 'stderr:\n', stderr )
				else:
					if len(stdout)>0:
						print 'stdout:\n', stdout
					if len(stderr)>0:
						print 'stderr:\n', stderr

				worker.finish()
				del self.workers[k]
				db.task_del( worker.call.cbid )


		timer.stop('work.finish.workers')
		return finished_worker_cnt
开发者ID:Nekel-Seyew,项目名称:cctools,代码行数:27,代码来源:worker_local.py


示例3: finish_workers

	def finish_workers( self ):
		timer.start('work.finish.workers')
		finished_worker_cnt = 0

		t = self.wq.wait(10)
		if t:
			worker = self.workers[t.id]
			print "WQ execution (%s) completed in %s: %s (return code %d)" % (worker.call.cbid, worker.sandbox, worker.call.body['cmd'], t.return_status)

			if t.return_status != 0:
				self.fails.append( worker.call )
				if worker.debug( t ):
					self.wq.blacklist( t.host )
					node = self.db.fetch( worker.call.key )
					self.execute( node.obj )
			else:
				worker.finish()
			self.worker_cnt -= 1
			del self.workers[t.id]
			db.task_del( worker.call.cbid )



		timer.stop('work.finish.workers')
		return finished_worker_cnt
开发者ID:Nekel-Seyew,项目名称:cctools,代码行数:25,代码来源:worker_wq.py


示例4: start_workers

	def start_workers( self ):
		global first_try

		timer.start('work.start.workers')
		started_worker_cnt = 0
		slots = glob.exec_local_concurrency - len(self.workers)
		batch = db.task_claim( slots )
		sys.stdout.write('.')
		sys.stdout.flush()
		if batch:
			calls = db.task_get( batch )
			for call in calls:
				self.execute( call )
				started_worker_cnt += 1
		elif len(self.workers)==0 and db.task_remain( glob.workflow_id )==0 and self.total_tasks>0:
			timer.report()
			return -2
			#sys.exit(0)

		if first_try:
			if started_worker_cnt==0:
				print 'Nothing to execute.'
				timer.report()
				return -1
				#sys.exit(0)
			first_try = False
		self.total_tasks += started_worker_cnt
		timer.stop('work.start.workers')
		return started_worker_cnt
开发者ID:Nekel-Seyew,项目名称:cctools,代码行数:29,代码来源:worker_local.py


示例5: task_get

	def task_get( self, batch ):
		calls = []
		timer.start('db.task.get')
		while True:
			try:

				conn, log = (self.tconn, self.tlog)
				with conn:
					curs = conn.cursor()
					curs.execute('SELECT cbid FROM todos WHERE assigned=?', (batch,) )
					res = curs.fetchall()

					for r in res:
						call = self.find_one( r['cbid'] )
						if call:
							calls.append( call )

			except sqlite3.OperationalError:
				print 'Database (todos) is locked on task_get'
				time.sleep(1)
				continue
			break

		timer.stop('db.task.get')
		return calls
开发者ID:Nekel-Seyew,项目名称:cctools,代码行数:25,代码来源:db_sqlite.py


示例6: hashstring

def hashstring( str ):
	timer.start('utils.hashstring')
	key = hashlib.sha1()
	key.update( str )
	key = key.hexdigest()
	timer.stop('utils.hashstring')
	return key
开发者ID:Nekel-Seyew,项目名称:cctools,代码行数:7,代码来源:utils.py


示例7: start_workers

	def start_workers( self ):
		global first_try

		timer.start('work.start.workers')
		started_worker_cnt = 0

		slots = self.wq.hungry()
		if slots==100:
			slots = 20
		#if slots>0 and slots<25:
		#	slots = 25
		batch = db.task_claim( slots )
		if batch:
			sys.stdout.write('.')
			sys.stdout.flush()
			calls = db.task_get( batch )

			for call in calls:
				self.execute( call )
				started_worker_cnt += 1
		elif len(self.workers)==0 and db.task_cnt()==0:
			time.sleep(5)
			sys.stdout.write(',')
			sys.stdout.flush()
			timer.report()
			return -1
			#sys.exit(0)
		self.total_tasks += started_worker_cnt
		timer.stop('work.start.workers')
		return started_worker_cnt
开发者ID:Nekel-Seyew,项目名称:cctools,代码行数:30,代码来源:worker_wq.py


示例8: task_prep

	def task_prep( self, item ):
		calls = []
		timer.start('db.task.prep')

		while True:
			try:
				conn, log = (self.tconn, self.tlog)
				with conn:

					# Check if task is already queued
					curs = conn.cursor()
					curs.execute('SELECT cbid FROM todos WHERE next_arg IN (?,?)', (item.cbid, item.dbid,) )
					res = curs.fetchall()

					for r in res:
						call = self.find_one( r['cbid'] )
						if call:
							# Update next_arg for task
							self.task_update( call )

			except sqlite3.OperationalError:
				print 'Database (todos) is locked on task_prep'
				time.sleep(1)
				continue
			break

		timer.stop('db.task.prep')
		return calls
开发者ID:Nekel-Seyew,项目名称:cctools,代码行数:28,代码来源:db_sqlite.py


示例9: unlink

    def unlink(self, m):
        timer.start("unlink")
        old_ant = self.ana_to_ant[m]
        if old_ant != -1:
            self.ana_to_ant[m] = -1
            self.ant_to_anas[old_ant].remove(m)

            old_c = self.mention_to_cluster[m]
            c1 = [m]
            frontier = self.ant_to_anas[m][:]
            while len(frontier) > 0:
                m = frontier.pop()
                c1.append(m)
                frontier += self.ant_to_anas[m]
            c1 = tuple(c1)
            c2 = tuple(m for m in old_c if m not in c1)

            self.update_b3(c1)
            self.update_b3(c2)

            self.clusters.remove(old_c)
            self.clusters.append(c1)
            self.clusters.append(c2)
            for m in c1:
                self.mention_to_cluster[m] = c1
            for m in c2:
                self.mention_to_cluster[m] = c2
        timer.stop("unlink")
开发者ID:clarkkev,项目名称:deep-coref,代码行数:28,代码来源:document.py


示例10: link

    def link(self, m1, m2, hypothetical=False, beta=1):
        timer.start("link")
        if m1 == -1:
            return self.get_f1(beta=beta) if hypothetical else None

        c1, c2 = self.mention_to_cluster[m1], self.mention_to_cluster[m2]
        assert c1 != c2
        new_c = c1 + c2
        p_num, r_num, p_den, r_den = self.p_num, self.r_num, self.p_den, self.r_den

        if len(c1) == 1:
            self.p_den += 1
        if len(c2) == 1:
            self.p_den += 1
        self.update_b3(new_c, hypothetical=hypothetical)

        if hypothetical:
            f1 = evaluation.f1(self.p_num, self.p_den, self.r_num, self.r_den, beta=beta)
            self.p_num, self.r_num, self.p_den, self.r_den = p_num, r_num, p_den, r_den
            timer.stop("link")
            return f1
        else:
            self.ana_to_ant[m2] = m1
            self.ant_to_anas[m1].append(m2)
            self.clusters.remove(c1)
            self.clusters.remove(c2)
            self.clusters.append(new_c)
            for m in new_c:
                self.mention_to_cluster[m] = new_c
        timer.stop("link")
开发者ID:clarkkev,项目名称:deep-coref,代码行数:30,代码来源:document.py


示例11: update_b3

    def update_b3(self, c, hypothetical=False):
        timer.start("update b3")
        if len(c) == 1:
            self.p_den -= 1
            self.p_num -= self.ps[c[0]]
            self.r_num -= self.rs[c[0]]
            self.ps[c[0]] = 0
            self.rs[c[0]] = 0
        else:
            intersect_counts = Counter()
            for m in c:
                if m in self.mention_to_gold:
                    intersect_counts[self.mention_to_gold[m]] += 1
            for m in c:
                if m in self.mention_to_gold:
                    self.p_num -= self.ps[m]
                    self.r_num -= self.rs[m]

                    g = self.mention_to_gold[m]
                    ic = intersect_counts[g]
                    self.p_num += ic / float(len(c))
                    self.r_num += ic / float(len(g))
                    if not hypothetical:
                        self.ps[m] = ic / float(len(c))
                        self.rs[m] = ic / float(len(g))
        timer.stop("update b3")
开发者ID:clarkkev,项目名称:deep-coref,代码行数:26,代码来源:document.py


示例12: connect

	def connect( self ):
		global dlog, clog

		timer.start('db.connect')

		self.dconn, dlog = self.sqlite3_connect(
			glob.data_db_pathname, glob.data_log_pathname, 'data_db_logger', glob.data_file_directory )

		self.cconn, clog = self.sqlite3_connect(
			glob.cache_db_pathname, glob.cache_log_pathname, 'cache_db_logger', glob.cache_file_directory )

		self.trconn, clog = self.sqlite3_connect(
			glob.trash_db_pathname, glob.trash_log_pathname, 'trash_db_logger', glob.trash_file_directory )

		self.tconn, self.tlog = self.sqlite3_connect( glob.work_db_pathname, glob.work_log_pathname )


		db_init_str = """
CREATE TABLE IF NOT EXISTS items (
	id INTEGER NOT NULL, type TEXT, cbid TEXT, dbid TEXT, wfid UUID, step TEXT,
	"when" FLOAT, meta TEXT, body TEXT, repo UUID, path TEXT, size INTEGER,
	PRIMARY KEY (id)
);

"""

		db_init_todos = """
CREATE TABLE IF NOT EXISTS todos (
	id INTEGER NOT NULL, cbid TEXT, wfid UUID, step TEXT, priority INTEGER DEFAULT 0,
	next_arg TEXT, assigned TEXT, failures INTEGER DEFAULT 0,
	PRIMARY KEY (id)
);

"""
		curs = self.dconn.cursor()
		curs.execute( db_init_str )
		curs.execute( 'CREATE INDEX IF NOT EXISTS itcbids ON items(cbid);' )
		curs.execute( 'CREATE INDEX IF NOT EXISTS itdbids ON items(dbid);' )
		self.dconn.commit()

		curs = self.cconn.cursor()
		curs.execute( db_init_str )
		curs.execute( 'CREATE INDEX IF NOT EXISTS itcbids ON items(cbid);' )
		curs.execute( 'CREATE INDEX IF NOT EXISTS itdbids ON items(dbid);' )
		self.cconn.commit()

		curs = self.trconn.cursor()
		curs.execute( db_init_str )
		curs.execute( 'CREATE INDEX IF NOT EXISTS itcbids ON items(cbid);' )
		curs.execute( 'CREATE INDEX IF NOT EXISTS itdbids ON items(dbid);' )
		self.trconn.commit()

		curs = self.tconn.cursor()
		curs.execute( db_init_todos )
		curs.execute( 'CREATE INDEX IF NOT EXISTS tdnext ON todos(next_arg, assigned);' )
		self.tconn.commit()
		self.tconn.isolation_level = 'EXCLUSIVE'

		timer.stop('db.connect')
开发者ID:Nekel-Seyew,项目名称:cctools,代码行数:59,代码来源:db_sqlite.py


示例13: evaluate_model

def evaluate_model(dataset, docs, model, model_props, stats, save_output=False, save_scores=False,
                   print_table=False):
    prog = utils.Progbar(dataset.n_batches)
    mt = RankingMetricsTracker(dataset.name, model_props=model_props) \
        if model_props.ranking else ClassificationMetricsTracker(dataset.name)
    mta = ClassificationMetricsTracker(dataset.name + " anaphoricity", anaphoricity=True)

    docs_by_id = {doc.did: doc for doc in docs} if model_props.ranking else {}
    saved_links, saved_scores = (defaultdict(list) if save_output else None,
                                 defaultdict(dict) if save_scores else None)
    for i, X in enumerate(dataset):
        if X['y'].size == 0:
            continue
        progress = []
        scores = model.predict_on_batch(X)
        if model_props.ranking:
            update_doc(docs_by_id[X['did']], X, scores,
                       saved_links=saved_links, saved_scores=saved_scores)
        if model_props.anaphoricity and not model_props.ranking:
            progress.append(("anaphoricity loss", mta.update(X, scores[0][:, 0])))
        if not model_props.anaphoricity_only:
            progress.append(("loss", mt.update(
                X, scores if model_props.ranking else
                scores[1 if model_props.anaphoricity else 0][:, 0])))
        prog.update(i + 1, exact=progress)

    if save_scores:
        print "Writing scores"
        utils.write_pickle(saved_scores, model_props.path + dataset.name + '_scores.pkl')
    if save_output:
        print "Writing output"
        utils.write_pickle(saved_links, model_props.path + dataset.name + '_links.pkl')
        utils.write_pickle(docs, model_props.path + dataset.name + '_processed_docs.pkl')

    timer.start("metrics")
    if model_props.ranking:
        stats.update(compute_metrics(docs, dataset.name))
    stats["validate time"] = time.time() - prog.start
    if model_props.anaphoricity and not model_props.ranking:
        mta.finish(stats)
    if not model_props.anaphoricity_only:
        mt.finish(stats)

    timer.stop("metrics")

    if print_table:
        print " & ".join(map(lambda x: "{:.2f}".format(x * 100), [
            stats[dataset.name + " muc precision"],
            stats[dataset.name + " muc recall"],
            stats[dataset.name + " muc"],
            stats[dataset.name + " b3 precision"],
            stats[dataset.name + " b3 recall"],
            stats[dataset.name + " b3"],
            stats[dataset.name + " ceafe precision"],
            stats[dataset.name + " ceafe recall"],
            stats[dataset.name + " ceafe"],
            stats[dataset.name + " conll"],
        ]))
开发者ID:clarkkev,项目名称:deep-coref,代码行数:58,代码来源:pairwise_learning.py


示例14: train

    def train(self):
        timer.start("train")
        X = self.memory.pop(int(random.random() * len(self.memory)))
        self.train_on_example(X)
        self.size -= 1
        timer.stop("train")

        if self.trainer.n == 1:
            print "Start training!"
            print
开发者ID:clarkkev,项目名称:deep-coref,代码行数:10,代码来源:clustering_learning.py


示例15: dump

	def dump( self, key, pathname ):
		timer.start('db.dump')

		item = self.find_one( key )
		if not item:
			print 'Not ready yet: %s' % key
		else:
			with open( pathname, 'w' ) as f:
				item.stream_content( f )

		timer.stop('db.dump')
开发者ID:Nekel-Seyew,项目名称:cctools,代码行数:11,代码来源:db_sqlite.py


示例16: insert

	def insert( self, item ):
		timer.start('db.insert')

		action_taken = 'exists'
		if item.type == 'temp':
			# This is an intermediate file, use the cache
			if not self.exists_temp_dbid( item.dbid ):
				conn, file_dir, log = (self.cconn, glob.cache_file_directory, clog)
				action_taken = 'saved'

		else:
			# This is not intermediate data, don't use cache
			if not self.exists_data( item ):
				conn, file_dir, log = (self.dconn, glob.data_file_directory, dlog)
				action_taken = 'saved'

		if action_taken == 'saved':
			if item.path:
				new_pathname = file_dir + item.cbid
				if not os.path.isfile( new_pathname ):
					shutil.move( item.path, new_pathname )
				item.path = item.cbid
			ins, vals = item.sqlite3_insert()
			#print ins
			#print vals
			while True:
				try:
					curs = conn.cursor()
					curs.execute( ins, vals )
					conn.commit()
				except sqlite3.OperationalError:
					print 'Database (todos) is locked on insert_exec'
					time.sleep(1)
					continue
				break

			self.task_prep( item )


			if item.type == 'temp':
				log.info('%s (%s) %s' % (item.cbid, item.dbid, action_taken))
			else:
				log.info('%s %s' % (item.cbid, action_taken))


		timer.stop('db.insert')

		#if glob.total_quota:
		#	self.keep_quota()

		if action_taken == 'saved':
			return True
		else:
			return False
开发者ID:Nekel-Seyew,项目名称:cctools,代码行数:54,代码来源:db_sqlite.py


示例17: action_costs

 def action_costs(self):
     timer.start("costs")
     costs = []
     for ant in self.candidate_antecedents:
         hypothetical_score = self.doc.link(ant, self.current_mention, hypothetical=True)
         costs.append(hypothetical_score)
     costs.append(self.get_f1())
     timer.stop("costs")
     costs = np.array(costs, dtype='float')
     costs -= costs.max()
     costs *= (len(self.doc.mention_to_gold) + len(self.doc.mentions)) / 100.0
     return -costs[:, np.newaxis]
开发者ID:clarkkev,项目名称:deep-coref,代码行数:12,代码来源:clustering_learning.py


示例18: hashfile

def hashfile( fname, blocksize=65536 ):
	timer.start('utils.hashfile')
	key = hashlib.sha1()
	afile = open( fname, 'rb' )
	buf = afile.read( blocksize )
	length = len( buf )
	while len( buf ) > 0:
		key.update( buf )
		buf = afile.read( blocksize )
		length += len( buf )
	key = key.hexdigest()
	timer.stop('utils.hashfile')
	return key, length
开发者ID:Nekel-Seyew,项目名称:cctools,代码行数:13,代码来源:utils.py


示例19: keep_quota

	def keep_quota( self, quota_bytes ):
		timer.start('db.keep_quota')

		consumption = self.quota_status()
		print '%i %i %i'%(time.time(), consumption, quota_bytes)

		if consumption <= quota_bytes:
			pass
			#print 'Under Quota by:', (quota_bytes-consumption)
		else:
			over_consumption = consumption-quota_bytes
			#print 'Over Quota by:', over_consumption
			file_cnt = 0
			while over_consumption>0:
				try:

					curs = self.cconn.cursor()
					trcurs = self.trconn.cursor()
					curs.execute('SELECT * FROM items ORDER BY id LIMIT 25;')
					res = curs.fetchall()
					timer.stop('db.keep_quota')

					cbids = []
					for r in res:
						it = Item(r)
						if it.dbid != '685aa1bae538a9f5dba28a55858467f82f5142a8:0':
							#shutil.copy( glob.cache_file_directory+it.path, glob.trash_file_directory+it.path )
							ins, dat = it.sqlite3_insert()
							trcurs.execute( ins, dat )
							cbids.append( it.cbid )
							over_consumption -= it.size
							if over_consumption <= 0:
								break
					self.trconn.commit()
					print '# %i files put in the trash'%(len(cbids))
					#timer.start('db.keep_quota')

					for cbid in cbids:
						pass
						#print ' -'+cbid
						curs.execute( "DELETE FROM items WHERE cbid=?;", (cbid,) )
					self.cconn.commit()


				except sqlite3.OperationalError:
					print 'Database (cache) is locked on keep_quota'
					time.sleep(1)
					continue
				file_cnt += len(cbids)
			return file_cnt
开发者ID:Nekel-Seyew,项目名称:cctools,代码行数:50,代码来源:db_sqlite.py


示例20: find_one

	def find_one( self, key ):
		timer.start('db.find_one')

		curs = self.dconn.cursor()
		curs.execute("SELECT * FROM items WHERE cbid=? ORDER BY id DESC LIMIT 1", (key,) )
		res = curs.fetchone()
		if not res:
			curs = self.cconn.cursor()
			curs.execute('SELECT * FROM items WHERE cbid=? OR dbid=? ORDER BY id DESC LIMIT 1', (key, key,) )
			res = curs.fetchone()
		if res:
			res = Item( res )
		timer.stop('db.find_one')
		return res
开发者ID:Nekel-Seyew,项目名称:cctools,代码行数:14,代码来源:db_sqlite.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python timer.stop函数代码示例发布时间:2022-05-27
下一篇:
Python timer.isRunning函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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