Added utils.utils.run_async as a simple wrapper to the Twisted deferred system. This allows for easily making a long-time-running process or command asynchronous.
This commit is contained in:
parent
547eb53b32
commit
31edce0ba1
2 changed files with 61 additions and 8 deletions
|
|
@ -7,8 +7,7 @@ from django.conf import settings
|
|||
from django.db import IntegrityError
|
||||
from src.comms.models import Msg
|
||||
from src.permissions import permissions
|
||||
from src.utils import create
|
||||
from src.utils import debug
|
||||
from src.utils import create, debug, utils
|
||||
from game.gamesrc.commands.default.muxcommand import MuxCommand
|
||||
|
||||
from src.commands import cmdsethandler
|
||||
|
|
@ -29,17 +28,38 @@ class CmdTest(MuxCommand):
|
|||
|
||||
key = "@test"
|
||||
aliases = ["@te", "@test all"]
|
||||
permissions = "cmd:Immortals Wizards"
|
||||
#permissions = "cmd:Immortals" #Wizards
|
||||
|
||||
# the muxcommand class itself handles the display
|
||||
# so we just defer to it by not adding any function.
|
||||
|
||||
def func(self):
|
||||
cmdsetname = "game.gamesrc.commands.default.cmdset_default.DefaultCmdSet"
|
||||
self.caller.msg(cmdsethandler.CACHED_CMDSETS)
|
||||
cmdsethandler.import_cmdset(cmdsetname, self, self)
|
||||
self.caller.msg("Imported %s" % cmdsetname)
|
||||
self.caller.msg(cmdsethandler.CACHED_CMDSETS)
|
||||
|
||||
def test():
|
||||
li = []
|
||||
for l in range(10000):
|
||||
li.append(l)
|
||||
self.caller.msg(li[-1])
|
||||
return "This is the return text"
|
||||
#print 1/0
|
||||
def succ(f):
|
||||
self.caller.msg("This is called after successful completion. Return value: %s" % f)
|
||||
def err(e):
|
||||
self.caller.msg("An error was encountered... %s" % e)
|
||||
|
||||
#self.caller.msg("printed before call to sync run ...")
|
||||
#test()
|
||||
#self.caller.msg("after after call to sync run...")
|
||||
|
||||
self.caller.msg("printed before call to async run ...")
|
||||
utils.run_async(test, at_return=succ, at_err=err)
|
||||
self.caller.msg("printed after call to async run ...")
|
||||
|
||||
#cmdsetname = "game.gamesrc.commands.default.cmdset_default.DefaultCmdSet"
|
||||
#self.caller.msg(cmdsethandler.CACHED_CMDSETS)
|
||||
#cmdsethandler.import_cmdset(cmdsetname, self, self)
|
||||
#self.caller.msg("Imported %s" % cmdsetname)
|
||||
#self.caller.msg(cmdsethandler.CACHED_CMDSETS)
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue