本文整理汇总了Python中the_tale.game.logic_storage.LogicStorage.on_exception方法的典型用法代码示例。如果您正苦于以下问题:Python LogicStorage.on_exception方法的具体用法?Python LogicStorage.on_exception怎么用?Python LogicStorage.on_exception使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类the_tale.game.logic_storage.LogicStorage
的用法示例。
在下文中一共展示了LogicStorage.on_exception方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Worker
# 需要导入模块: from the_tale.game.logic_storage import LogicStorage [as 别名]
# 或者: from the_tale.game.logic_storage.LogicStorage import on_exception [as 别名]
class Worker(workers.BaseWorker):
STOP_SIGNAL_REQUIRED = False
def initialize(self):
# worker initialized by supervisor
pass
def cmd_initialize(self, turn_number, worker_id):
self.send_cmd('initialize', {'turn_number': turn_number, 'worker_id': worker_id})
def process_initialize(self, turn_number, worker_id):
if self.initialized:
self.logger.warn('WARNING: game already initialized, do reinitialization')
self.storage = LogicStorage()
self.initialized = True
self.turn_number = turn_number
self.queue = []
self.worker_id = worker_id
self.logger.info('GAME INITIALIZED')
environment.workers.supervisor.cmd_answer('initialize', self.worker_id)
def cmd_next_turn(self, turn_number):
return self.send_cmd('next_turn', data={'turn_number': turn_number})
# @profile.profile_decorator('/home/tie/repos/mine/the-tale/profile.info')
def process_next_turn(self, turn_number):
self.turn_number += 1
if turn_number != self.turn_number:
raise LogicException('dessinchonization: workers turn number (%d) not equal to command turn number (%d)' % (self.turn_number, turn_number))
if TimePrototype.get_current_turn_number() != self.turn_number:
raise LogicException('dessinchonization: workers turn number (%d) not equal to saved turn number (%d)' % (self.turn_number,
TimePrototype.get_current_turn_number()))
self.storage.process_turn(logger=self.logger)
self.storage.save_changed_data(logger=self.logger)
for hero_id in self.storage.skipped_heroes:
hero = self.storage.heroes[hero_id]
if hero.actions.current_action.bundle_id in self.storage.ignored_bundles:
continue
environment.workers.supervisor.cmd_account_release_required(hero.account_id)
environment.workers.supervisor.cmd_answer('next_turn', self.worker_id)
if game_settings.COLLECT_GARBAGE and self.turn_number % game_settings.COLLECT_GARBAGE_PERIOD == 0:
self.logger.info('GC: start')
gc.collect()
self.logger.info('GC: end')
def release_account(self, account_id):
if account_id not in self.storage.accounts_to_heroes:
environment.workers.supervisor.cmd_account_released(account_id)
return
hero = self.storage.accounts_to_heroes[account_id]
bundle_id = hero.actions.current_action.bundle_id
if bundle_id in self.storage.ignored_bundles:
return
with self.storage.on_exception(self.logger,
message='LogicWorker.process_release_account catch exception, while processing hero %d, try to save all bundles except %d',
data=(hero.id, bundle_id),
excluded_bundle_id=bundle_id):
self.storage.release_account_data(account_id)
environment.workers.supervisor.cmd_account_released(account_id)
def cmd_stop(self):
return self.send_cmd('stop')
def process_stop(self):
# no need to save data, since they automaticaly saved on every turn
self.initialized = False
self.storage.save_all(logger=self.logger)
environment.workers.supervisor.cmd_answer('stop', self.worker_id)
self.stop_required = True
self.logger.info('LOGIC STOPPED')
def cmd_register_account(self, account_id):
return self.send_cmd('register_account', {'account_id': account_id})
def process_register_account(self, account_id):
from the_tale.accounts.prototypes import AccountPrototype
account = AccountPrototype.get_by_id(account_id)
if account is None:
raise LogicException('can not get account with id "%d"' % (account_id,))
self.storage.load_account_data(account)
def cmd_release_account(self, account_id):
return self.send_cmd('release_account', {'account_id': account_id})
#.........这里部分代码省略.........