本文整理汇总了Python中util.current_time函数的典型用法代码示例。如果您正苦于以下问题:Python current_time函数的具体用法?Python current_time怎么用?Python current_time使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了current_time函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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) # 删除上传的临时文件
示例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
示例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
示例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))
示例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)
示例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()))
示例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)
示例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)
示例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"
示例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)
示例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)
示例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
示例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) # 删除上传的临时文件
示例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))