本文整理汇总了Python中util.current_time函数的典型用法代码示例。如果您正苦于以下问题:Python current_time函数的具体用法?Python current_time怎么用?Python current_time使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了current_time函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, server=None, message=None, reply_listener=None, internal_channel=None, timeout=1000000, max_retries=3):
self.logger = logging.getLogger('{}'.format(self.__class__.__name__))
self.logger.debug('__init__')
self.logger.debug('__init__. node_hash: {}'.format(server.node_hash))
self._server = server
self._message = message
self._reply_listener = reply_listener
self._internal_channel = internal_channel
# for communications
self._complete = False
self._replies = dict()
self._channels = list()
# for timeouts
self._timeout = util.add_time(util.current_time(), timeout)
self._retries = dict()
self._max_retries = max_retries
self._outgoing_message = None
#listener and processor
self._coordinator_listener = self._listener(self._server.num_replicas)
self._processor = self._request_handler(message=message, reply_listener=reply_listener, internal_channel=internal_channel)
开发者ID:samuelwu90,项目名称:PynamoDB,代码行数:25,代码来源:internal_request_stage.py
示例2: monthly_card_import
def monthly_card_import(db):
data = request.files.data
error = ''
all_sqls = IMPORT_SQLS
if data and data.file:
tmp_root = './tmp/'
if not isdir(tmp_root): # 若目录tmp_root不存在,则创建
os.mkdir(tmp_root)
tmp_filename = os.path.join(tmp_root, current_time('tmp_monthly_card%Y%m%d%H%M%S.xls'))
tmp_file = open(tmp_filename, 'w') # 新建一个xls后缀的文件,然后将读取的excel文件的内容写入该文件中
rows = data.file.readlines()
if not rows: # 文件空
error = '数据格式错误[2]'
return template('error', error=error)
for row in rows:
tmp_file.write(row)
tmp_file.close()
# 在导入新的数据前,先将数据库原有数据导出到tmp目录,作为备份,数据导入失败时可以恢复数据
export_sqls = EXPORT_SQLS
try:
# 若备份文件已存在,则删除重新写入
if os.path.exists(os.path.join(tmp_root, BACK_FILE)):
os.remove(os.path.join(tmp_root, BACK_FILE))
excel_export(export_sqls, tmp_root, BACK_FILE, db)
except Exception, e:
print '数据备份错误: %s' %e
error = excel_import(all_sqls, tmp_filename, db)
os.remove(tmp_filename) # 删除上传的临时文件
开发者ID:anson-tang,项目名称:3dkserver,代码行数:32,代码来源:monthly_card.py
示例3: timed_out
def timed_out(self):
"""
Returns:
----------
True if self has timed out i.e. current time is past the set timeout time.
False otherwise.
"""
return util.current_time() > self._timeout
开发者ID:samuelwu90,项目名称:PynamoDB,代码行数:8,代码来源:internal_request_stage.py
示例4: authenticate
def authenticate(self):
while not self.user:
username = self.read()
user = self.server.users.get(username)
if not user:
self.send_line('register')
register = self.read()
if register == 'y':
self.send_line('password')
password = self.read()
while password != self.read():
self.send_line('password')
password = self.read()
self.send_line('registered')
self.register_user(username, password)
else:
self.send_line('username')
elif self.ip in user.blocked_ips:
time_blocked = user.blocked_ips[self.ip]
time_elapsed = util.current_time() - time_blocked
time_left = self.block_time - time_elapsed
if time_elapsed > self.block_time:
user.blocked_ips.pop(self.ip)
self.user = user
else:
self.send_line('blocked:{}'.format(time_left))
return False
elif user.is_connected:
self.send_line('connected')
else:
self.user = user
login_attempts = 0
while login_attempts < 3:
self.send_line('password')
password = self.read()
if self.user.password_sha == util.sha1_hex(password):
self.send_line('welcome')
return True
login_attempts += 1
self.send_line(str(self.block_time))
self.user.blocked_ips[self.ip] = util.current_time()
self.log('{} blocked for {} seconds'.format(
username,
self.block_time
))
return False
开发者ID:javierllaca,项目名称:chatserv,代码行数:46,代码来源:server.py
示例5: last
def last(self, number):
usernames = []
ref_time = util.current_time()
for user in self.server.users.values():
minutes = float(ref_time - user.last_active) / 60
if user.is_connected or minutes < number:
usernames.append(user.username)
self.send_line(' '.join(usernames))
开发者ID:javierllaca,项目名称:chatserv,代码行数:8,代码来源:server.py
示例6: _send_message
def _send_message(self, message):
"""
Sends message back to client.
"""
self.logger.debug('_send_message.')
self.logger.debug('_send_message. message {}'.format(message))
self.push(util.pack_message(message, self._server._terminator))
# set timeout to be 30 seconds after last request received
self._timeout = util.add_time(util.current_time(), 30)
开发者ID:samuelwu90,项目名称:PynamoDB,代码行数:10,代码来源:external_request_stage.py
示例7: _handle_membership_checks
def _handle_membership_checks(self):
self.logger.debug('_handle_membership_checks')
next_check_time = util.add_time(util.current_time(), self._wait_time)
while True:
# handle failures
try:
to_be_removed = []
for node_hash in self._failed_to_contact_node_hashes:
count = self._failed_to_contact_node_hashes[node_hash]['count']
if count >= 3:
if node_hash in self.node_hashes:
self._server.internal_request_stage.handle_unannounced_failure(failure_node_hash=node_hash)
to_be_removed.append(node_hash)
# flush stale contact failures
for node_hash in self._failed_to_contact_node_hashes:
timeout = self._failed_to_contact_node_hashes[node_hash]['timeout']
if util.current_time() > timeout:
to_be_removed.append(node_hash)
for node_hash in list(set(to_be_removed)):
try:
del self._failed_to_contact_node_hashes[node_hash]
except:
pass
# retry contacting failure node hashes:
for node_hash in self._failed_to_contact_node_hashes:
if util.current_time() > self._failed_to_contact_node_hashes[node_hash]['timeout']:
self._server.internal_request_stage.handle_membership_check(gossip_node_hash=node_hash)
if util.current_time() > next_check_time:
self._server.internal_request_stage.handle_membership_check()
next_check_time = util.add_time(util.current_time(), 1)
yield
else:
yield
except Exception as e:
self.logger.error('_handle_membership_checks error: {}, {}'.format(e, sys.exc_info()))
开发者ID:samuelwu90,项目名称:PynamoDB,代码行数:39,代码来源:membership_stage.py
示例8: monthly_card_export
def monthly_card_export(db):
tmp_root = './tmp/'
filename = current_time(excel_export_filename) # 文件名
error = ''
if not isfile(tmp_root + filename):
all_sqls = EXPORT_SQLS
error = excel_export(all_sqls, tmp_root, filename, db)
if error:
return template('error', error=error)
else:
return static_file(filename, root = tmp_root, download = filename)
开发者ID:anson-tang,项目名称:3dkserver,代码行数:13,代码来源:monthly_card.py
示例9: lover_kiss_export
def lover_kiss_export(db):
tmp_root = './tmp/'
filename = current_time("lover_kiss_%Y%m%d%H%M.xls") # 文件名
error = ''
if not isfile(tmp_root + filename):
all_sqls = EXPORT_SQLS
error = excel_export(all_sqls, tmp_root, filename, db)
if error:
return template('error', error=error)
else:
return static_file(filename, root = tmp_root, download = filename)
开发者ID:anson-tang,项目名称:3dkserver,代码行数:13,代码来源:lover_kiss.py
示例10: incoming_sms
def incoming_sms(user_id):
sms = {
"_plivo_uuid": request.form['MessageUUID'],
"_user_id": user_id,
"from": request.form['From'],
"to": request.form['To'],
"caller_name": "",
"time_received": current_time(),
"body": request.form['Text']
}
mongo.db.sms.insert(sms)
return "OK"
开发者ID:RKJuve,项目名称:onering.io,代码行数:13,代码来源:app.py
示例11: keyword_export
def keyword_export(lang, db):
tmp_root = './tmp/'
filename = current_time("keyword_%Y%m%d%H%M.xls") # 文件名
error = ''
_table = 'tb_keyword_%s' % lang if lang and lang != '0' else table_name
all_sqls = { _table : [sql_base_tpl.format( _table ), field_base, 'Message'] }
if not isfile(tmp_root + filename):
error = excel_export(all_sqls, tmp_root, filename, db)
if error:
return template('error', error=error)
else:
return static_file(filename, root = tmp_root, download = filename)
开发者ID:anson-tang,项目名称:3dkserver,代码行数:15,代码来源:keyword.py
示例12: report_contact_failure
def report_contact_failure(self, node_hash=None):
self.logger.debug('report_contact_failure')
try:
self._failed_to_contact_node_hashes[node_hash]['count'] += 1
except:
self._failed_to_contact_node_hashes[node_hash]['count'] = 1
try:
timeout = self._failed_to_contact_node_hashes[node_hash]['timeout']
new_timeout = util.add_time(timeout, 10)
except:
new_timeout = util.add_time(util.current_time(), 10)
finally:
self._failed_to_contact_node_hashes[node_hash]['timeout'] = new_timeout
self._failed_to_contact_node_hashes[node_hash]['next_check_time'] = util.add_time(util.current_time(), 1)
开发者ID:samuelwu90,项目名称:PynamoDB,代码行数:17,代码来源:membership_stage.py
示例13: process
def process(self):
"""
Processes request queue and returns replies in the correct order when they are ready.
"""
self.logger.debug('process')
# if timeout has been set and it's past the time
if self._timeout and (util.current_time() > self._timeout):
self.close_when_done()
pass
# process requests
for coordinator in self._coordinators:
coordinator.process()
# send replies if ready
for index, coordinator in enumerate(self._coordinators):
if coordinator.completed:
self._send_message(coordinator._reply)
self._coordinators.pop(0)
else:
break
开发者ID:samuelwu90,项目名称:PynamoDB,代码行数:22,代码来源:external_request_stage.py
示例14: keyword_import
def keyword_import(db):
data = request.files.data
error = ''
lang_id = int(request.forms.lang)
_table = 'tb_keyword_%s' % lang_id if lang_id and lang_id != '0' else table_name
all_sqls = { 'Message' : [insert_sql.format( _table ), _table] }
export_sqls = { _table : [sql_base_tpl.format( _table ), field_base, 'Message'] }
if data and data.file:
tmp_root = './tmp/'
if not isdir(tmp_root): # 若目录tmp_root不存在,则创建
os.mkdir(tmp_root)
tmp_filename = os.path.join(tmp_root, current_time('tmpkeyword_%Y%m%d%H%M%S.xls'))
tmp_file = open(tmp_filename, 'w') # 新建一个xls后缀的文件,然后将读取的excel文件的内容写入该文件中
rows = data.file.readlines()
if not rows: # 文件空
error = '数据格式错误[2]'
return template('error', error=error)
for row in rows:
tmp_file.write(row)
tmp_file.close()
# 在导入新的数据前,先将数据库原有数据导出到tmp目录,作为备份,数据导入失败时可以恢复数据
try:
# 若备份文件已存在,则删除重新写入
if os.path.exists(os.path.join(tmp_root, BACK_FILE)):
os.remove(os.path.join(tmp_root, BACK_FILE))
excel_export(export_sqls, tmp_root, BACK_FILE, db)
except Exception, e:
print '数据备份错误: %s' %e
error = excel_import(all_sqls, tmp_filename, db)
os.remove(tmp_filename) # 删除上传的临时文件
开发者ID:anson-tang,项目名称:3dkserver,代码行数:36,代码来源:keyword.py
示例15: _process_message
def _process_message(self, request):
"""
Handles request messages passed from async_chat's found_terminator handler.
-marks message as 'exteral request' and gives it a timestamp. Hashes key before passing the request internally by instantiating an ExternalRequestCoordinator.
Args:
----------
request : JSON
incoming request object.
"""
self.logger.debug('_request_handler.')
request['type'] = 'external request'
request['timestamp'] = util.current_time()
try
request['key'] = util.get_hash(request['key'])
except:
pass
coordinator = ExternalRequestCoordinator(server=self._server, request=request)
self._coordinators.append(coordinator)
self.logger.debug('_request_handler. coordinator appended: {}'.format(coordinator))
开发者ID:samuelwu90,项目名称:PynamoDB,代码行数:24,代码来源:external_request_stage.py
示例16: timeout
def timeout(self):
return util.current_time() - self.timer_start > self.timeout_interval
开发者ID:javierllaca,项目名称:simple-TCP,代码行数:2,代码来源:sender.py
示例17: update_stats
def update_stats(self):
self.sample_rtt = util.current_time() - self.timer_start
self.estimated_rtt = 0.875 * self.estimated_rtt + 0.125 * self.sample_rtt
self.dev_rtt = 0.75 * self.dev_rtt + 0.25 * abs(
self.sample_rtt - self.estimated_rtt)
self.timeout_interval = self.estimated_rtt + 4 * self.dev_rtt
开发者ID:javierllaca,项目名称:simple-TCP,代码行数:6,代码来源:sender.py
示例18: reset_timer
def reset_timer(self):
self.timer_start = util.current_time()
开发者ID:javierllaca,项目名称:simple-TCP,代码行数:2,代码来源:sender.py
示例19: make_prints_3
def make_prints_3 (lang, ori):
ori = os.path.realpath(ori)
dat = util.current_time()
usr = util.get_username()
hst = util.get_hostname()
src = "%[email protected]%s:%s" % (usr, hst, ori)
sample2 = ""
sample1 = ""
tsts = sorted(glob.glob("*sample*.inp"))
i = 0
for j in tsts:
i += 1
jj = os.path.splitext(j)[0]
if len(tsts)==1: num = ""
else: num = str(i)
sample2 += r"\SampleTwoColInputOutput{%s}{%s}" % (jj,num)
sample1 += r"\SampleOneColInputOutput{%s}{%s}" % (jj,num)
scores = ""
if util.file_exists("scores.yml"):
scores = "scores.yml: \\verbatimtabinput{scores.yml}"
t = r"""
\documentclass[11pt]{article}
\usepackage{vanilla}
\usepackage{vanilla.%s}
\[email protected]
\begin{document}
\newcommand{\SampleTwoCol}{%s}
\newcommand{\SampleOneCol}{%s}
\DoProblem{%s}
\subsection*{Metadata}
\begin{verbatim}
language: %s
source: %s
generation-time: %s\end{verbatim}
problem.%s.yml: \verbatimtabinput{problem.%s.yml}
handler.yml: \verbatimtabinput{handler.yml}
%s
\end{document}
""" % (lang, sample2, sample1, lang, lang, src, dat, lang, lang, scores)
util.write_file("main.tex", t)
print "latex"
r = os.system("latex -interaction scrollmode main > main.err")
#r = os.system("latex main")
if r != 0:
os.system('cat main.err')
raise Exception("latex error")
print "dvips"
r = os.system("dvips main -o 1> /dev/null 2>/dev/null")
if r != 0: raise Exception("dvips error")
print "ps2pdf"
r = os.system("ps2pdf main.ps main.pdf 1> /dev/null 2>/dev/null")
if r != 0: raise Exception("ps2pdf error")
os.system("mv main.ps %s/problem.%s.ps " % (ori, lang))
os.system("mv main.pdf %s/problem.%s.pdf" % (ori, lang))
开发者ID:jutge-org,项目名称:toolkit,代码行数:67,代码来源:problems.py
注:本文中的util.current_time函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论