Added example of how to handle event errors gracefully without them taking down the server with with unhandled exceptions (this should be handled somewhere above exception too, but it's hard to tell when to do it since twisted is raising them). /Starkiel

This commit is contained in:
Griatch 2009-04-30 08:23:54 +00:00
parent b53c228257
commit 8799a0fd55
5 changed files with 20 additions and 7 deletions

View file

@ -8,6 +8,7 @@ objects inheriting to a particular script parent and calls one of its functions
at a regular interval.
"""
import sys
from src.events import IntervalEvent
from src.scheduler import add_event
from src.objects.models import Object
@ -48,7 +49,16 @@ class EventBlinkButton(IntervalEvent):
#log_infomsg("buttons found: %s" % buttons)
for b in buttons:
b.scriptlink.blink()
try:
b.scriptlink.blink()
except AttributeError:
#button has no blink() method. Just ignore.
pass
except:
#show other tracebacks to owner of object.
#this is important, we must handle this exception
#gracefully!
b.get_owner().emit_to(sys.exc_info()[1])
#create and add the event to the global handler
blink_event = EventBlinkButton()

View file

@ -15,9 +15,11 @@ test button you must drop it before you will see its messages!
from game.gamesrc.parents.base.basicobject import BasicObject
#you have to import the event definition(s) from somewhere covered by @reload,
# - this is as good a place as any. Uncomment to turn off event system.
# - this is as good a place as any.
import game.gamesrc.events.example
import game.gamesrc.events.eventSystem
#
#commands on the button object
#
@ -98,6 +100,10 @@ class RedButton(BasicObject):
count += 1
obj.set_attribute("count",count)
obj.get_location().emit_to_contents(s)
def update_tick(self):
self.blink()
def class_factory(source_obj):
"""

View file

@ -84,8 +84,7 @@ class ObjectManager(models.Manager):
"""
o_query = self.filter(script_parent__exact=script_parent)
return o_query.exclude(type__in=[defines_global.OTYPE_GARBAGE,
defines_global.OTYPE_GOING])
defines_global.OTYPE_GOING])
def list_search_object_namestr(self, searchlist, ostring, dbref_only=False,
limit_types=False, match_type="fuzzy"):

View file

@ -24,8 +24,6 @@ def add_event(event):
#don't add multiple instances of the same event
if event in schedule:
return
#i = schedule.index(event)
#schedule[i] = event
else:
schedule.append(event)
event.start_event_loop()

View file

@ -173,7 +173,7 @@ class SessionProtocol(StatefulTelnetProtocol):
self.pobject.scriptlink.at_pre_login(self)
self.pobject.scriptlink.at_post_login(self)
logger.log_infomsg("Loged in: %s" % self)
logger.log_infomsg("Logged in: %s" % self)
self.cemit_info('Logged in: %s' % self)
# Update their account's last login time.