本文整理汇总了Python中store.Store.update方法的典型用法代码示例。如果您正苦于以下问题:Python Store.update方法的具体用法?Python Store.update怎么用?Python Store.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类store.Store
的用法示例。
在下文中一共展示了Store.update方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import update [as 别名]
def update(item_id):
temp = request.json
if len(temp) > 6 or "_id" in temp or len(temp)<1:
abort(400)
res = Store.update(str(item_id),temp)
if res==404:
abort(404)
print res
return jsonify(res), 200
示例2: AsyncMusicPlayer
# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import update [as 别名]
class AsyncMusicPlayer(threading.Thread):
'''Music Player.
MusicPlayer가 동기적이기 때문에 이것을 비동기적으로 명령을 처리
하기 위해서 Thread로 만듬
외부와의 데이터 교환:
- playlist : 플레이 리스트
- command_list : 명령 수행
'''
def __init__(self):
threading.Thread.__init__(self)
# 현재 플레이 중인 Url
self.url = ''
# 현재 플레이 되고 있는 노래
self.current_song = None
# webbrowser player 인스턴스
self.player = MusicPlayer()
# DB
self.store = Store()
def run(self):
'이 쓰레드에서 수행할 로직'
while True:
try:
# 0.5초를 주기로 명령 수행
time.sleep(0.5)
# 광고가 나오는지 확인해서 넘긴다.
# 보통 youtube 광고는 5초다.
# TODO: 광고가 나오면 volume을 줄이도록 한다.
self.player.skip_if_exists_ad()
if self.url == '':
self.play_next_song()
# URL이 변경되었으면 표시한다.
url = self.player.current_url()
if( self.url != url ):
self.url = url
# TODO:
# - 여기에서 곡을 추가하는 로직을 넣으면
# - 내가 듣는 링크를 플레이 리스트로 만들 수 있다.
print(self.url)
# 노래가 중지되면 다음 노래
if self.player.is_finished() :
# played_count 수를 하나 증가 시킨다.
if self.current_song:
self.current_song.played_count += 1
self.store.update(self.current_song)
self.play_next_song()
elif self.player.is_unplable():
self.play_next_song()
self.handle_cmd();
except queue.Empty:
pass
except KeyboardInterrupt:
break
except Exception as e:
# 에러가 발생하면 에러의 종료를 출력
#print('----')
#print(type(e))
#print(e)
break
def play_next_song(self):
" 다음 곡 "
# 플레이 리스트에서 하나 꺼낸다.
playlist_lock.acquire()
try:
song = playlist.pop(0)
url = song.url
except:
url = None
playlist_lock.release()
# url이 있으면 다음곡 플레이
if url:
self.current_song = song
self.player.play_url(song.url)
def stop(self):
" 일시 정지 "
self.player.stop()
def play(self):
" 다시 플레이"
self.player.play()
def handle_cmd(self):
#.........这里部分代码省略.........
示例3: __init__
# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import update [as 别名]
class KvPaxosServer:
def __init__(self):
with open(str(ME) + 'log.txt', 'w') as file:
file.write('log:\n')
self.px = Paxos.make(HOSTS_LIST, ME)
self.http_server = BaseHTTPServer.HTTPServer(
(HOST, int(PORT)), MyHTTPRequestHandler)
self.kvstore = Store()
self.keep_running = True
self.lock = Lock()
# do not modify these 2 vars outside the execute() function
# lock required to access these values. # maybe unnecessary
self.executed_paxos_no = 0
# contains all executed operations and their return values
self.operation_log = []
self.processed_requestid = dict()
def start(self):
log("HTTP Server Starts - %s:%s" % (HOST, PORT))
maintainance_thread = Thread(target=self.maintainance, name='maintainance')
maintainance_thread.start()
try:
while self.keep_running:
# self.http_server.serve_forever()
self.http_server.handle_request()
except KeyboardInterrupt:
sys.exit(0)
maintainance_thread.join()
os._exit(0)
def maintainance(self):
while self.keep_running:
while self.px.max() < self.executed_paxos_no and self.keep_running:
# print 'maintainance sleep'
time.sleep(MAX_SLEEP_TIME)
if self.keep_running:
# print 'maintainance execute', self.px.max(), self.executed_paxos_no
self.execute(self.executed_paxos_no, None)
''' this function is only called by the handler class, & the maintainance thread'''
def execute(self, seq, requestid):
# catch up. this ensures that operations are executed in ascending order
while self.executed_paxos_no < seq:
time.sleep(MAX_SLEEP_TIME)
with self.lock:
# print 'lock acquired ============================================================'
# if seq < self.executed_paxos_no:
# # the operations is done by other threads already, check the log directly
# return operation_log[seq].return_value
if self.processed_requestid.has_key(requestid):
assert self.processed_requestid[requestid] < self.executed_paxos_no
return self.operation_log[self.processed_requestid[requestid]].return_value
# this request has not been executed yet, or is being executed by maintainance thread.
while True:
# since not executed, it cannot be forgotten
decided, op_jstr = self.px.status(seq)
if decided:
break
else:
# print 'waiting for decided value', seq, op_jstr
time.sleep(MAX_SLEEP_TIME)
op = Operation.decode(op_jstr)
assert decided
if self.processed_requestid.has_key(op.requestid):
success, value = self.operation_log[self.processed_requestid[op.requestid]].return_value
else:
if op.op_type == 'GET':
success, value = self.kvstore.get(op.key)
elif op.op_type == 'INSERT':
success, value = self.kvstore.insert(op.key, op.value)
elif op.op_type == 'DELETE':
success, value = self.kvstore.delete(op.key)
elif op.op_type == 'UPDATE':
success, value = self.kvstore.update(op.key, op.value)
self.executed_paxos_no += 1
# self.px.done(seq)
op.done((success, value))
self.operation_log += [op]
assert (not self.processed_requestid.has_key(op.requestid)) or requestid is None
if not self.processed_requestid.has_key(op.requestid):
self.processed_requestid[op.requestid] = seq
# print self.processed_requestid
with open(str(ME) + 'log.txt', 'a') as file:
file.write(op.encode() + '\n')# + str(self.processed_requestid) + '\n')
return success, value
def handle_shutdown(self):
self.keep_running = False