Fixed @batchcommand access, automatically disabling procpool under SQLite3.

This commit is contained in:
Griatch 2012-09-27 20:51:06 +02:00
parent b28d67534b
commit 0b102bb07b
3 changed files with 53 additions and 10 deletions

1
ev.py
View file

@ -236,3 +236,4 @@ class SystemCmds(object):
del cmdhandler
syscmdkeys = SystemCmds()
del SystemCmds

View file

@ -65,15 +65,15 @@ for inum in range(len(commands)):
print "leaving run ..."
"""
_PROCPOOL_BATCHCODE_SOURCE = """
from src.commands.default.batchprocess import batch_cmd_exec, step_pointer, BatchSafeCmdSet
caller.ndb.batch_stack = commands
from src.commands.default.batchprocess import batch_code_exec, step_pointer, BatchSafeCmdSet
caller.ndb.batch_stack = codes
caller.ndb.batch_stackptr = 0
caller.ndb.batch_batchmode = "batch_commands"
caller.ndb.batch_batchmode = "batch_code"
caller.cmdset.add(BatchSafeCmdSet)
for inum in range(len(commands)):
print "command:", inum
for inum in range(len(codes)):
print "code:", inum
caller.cmdset.add(BatchSafeCmdSet)
if not batch_cmd_exec(caller):
if not batch_code_exec(caller):
break
step_pointer(caller, 1)
print "leaving run ..."
@ -272,7 +272,14 @@ class CmdBatchCommands(MuxCommand):
else:
caller.msg("Running Batch-command processor - Automatic mode for %s (this might take some time) ..." % python_path)
if False:#TODO - need to add a procpool solution. settings.PROCPOOL_ENABLED:
procpool = False
if "PythonProcPool" in utils.server_services():
if utils.uses_database("sqlite3"):
caller.msg("Batchprocessor disabled ProcPool under SQLite3.")
else:
procpool=True
if procpool:
# run in parallel process
def callback(r):
caller.msg(" {GBatchfile '%s' applied." % python_path)
@ -366,7 +373,13 @@ class CmdBatchCode(MuxCommand):
else:
caller.msg("Running Batch-code processor - Automatic mode for %s ..." % python_path)
if False: #TODO Add procpool solution. settings.PROCPOOL_ENABLED:
procpool = False
if "PythonProcPool" in utils.server_services():
if utils.uses_database("sqlite3"):
caller.msg("Batchprocessor disabled ProcPool under SQLite3.")
else:
procpool=True
if procpool:
# run in parallel process
def callback(r):
caller.msg(" {GBatchfile '%s' applied." % python_path)
@ -374,10 +387,10 @@ class CmdBatchCode(MuxCommand):
def errback(e):
caller.msg(" {RError from processor: '%s'" % e)
purge_processor(caller)
utils.run_async(_PROCPOOL_BATCHCODE_SOURCE, commands=commands, caller=caller, at_return=callback, at_err=errback)
utils.run_async(_PROCPOOL_BATCHCODE_SOURCE, codes=codes, caller=caller, at_return=callback, at_err=errback)
else:
# un in-process (will block)
for inum in range(len(commands)):
for inum in range(len(codes)):
# loop through the batch file
if not batch_cmd_exec(caller):
return

View file

@ -461,6 +461,35 @@ def format_table(table, extra_space=1):
for icol, col in enumerate(table)])
return ftable
def server_services():
"""
Lists all services active on the Server. Observe that
since services are launced in memory, this function will
only return any results if called from inside the game.
"""
from src.server.sessionhandler import SESSIONS
if hasattr(SESSIONS, "server") and hasattr(SESSIONS.server, "services"):
server = SESSIONS.server.services.namedServices
else:
print "This function must be called from inside the evennia process."
server = {}
del SESSIONS
return server
def uses_database(name="sqlite3"):
"""
Checks if the game is currently using a given database. This is a
shortcut to having to use the full backend name
name - one of 'sqlite3', 'mysql', 'postgresql_psycopg2' or 'oracle'
"""
try:
engine = settings.DATABASES["default"]["ENGINE"]
except KeyError:
engine = settings.DATABASE_ENGINE
return engine == "django.db.backends.%s" % name
_FROM_MODEL_MAP = None
_TO_DBOBJ = lambda o: (hasattr(o, "dbobj") and o.dbobj) or o