Browse Source

Release manager's _resource_access_lock before processing a command so it can reload itself

tags/v0.1^2
Ben Kurtovic 12 years ago
parent
commit
cc6a4c6b99
2 changed files with 21 additions and 12 deletions
  1. +14
    -2
      earwigbot/commands/__init__.py
  2. +7
    -10
      earwigbot/managers.py

+ 14
- 2
earwigbot/commands/__init__.py View File

@@ -57,10 +57,22 @@ class BaseCommand(object):
self.config = bot.config
self.logger = bot.commands.logger.getChild(self.name)

def _wrap_check(self, data):
"""Check whether this command should be called, catching errors."""
try:
return self.check(data)
except Exception:
e = "Error checking command '{0}' with data: {1}:"
self.logger.exception(e.format(self.name, data))

def _wrap_process(self, data):
"""Make a quick connection alias and then process() the message."""
"""Make a connection alias, process() the message, and catch errors."""
self.connection = self.bot.frontend
self.process(data)
try:
self.process(data)
except Exception:
e = "Error executing command '{0}':"
self.logger.exception(e.format(data.command))

def check(self, data):
"""Return whether this command should be called in response to 'data'.


+ 7
- 10
earwigbot/managers.py View File

@@ -149,16 +149,13 @@ class CommandManager(_ResourceManager):

def check(self, hook, data):
"""Given an IRC event, check if there's anything we can respond to."""
with self.lock:
for command in self._resources.itervalues():
if hook in command.hooks:
if command.check(data):
try:
command._wrap_process(data)
except Exception:
e = "Error executing command '{0}':"
self.logger.exception(e.format(data.command))
break
self.lock.acquire()
for command in self._resources.itervalues():
if hook in command.hooks and command._wrap_check(data):
self.lock.release()
command._wrap_process(data)
return
self.lock.release()


class TaskManager(_ResourceManager):


Loading…
Cancel
Save