Added a timeout to the attribute caching; the system will now clean cache at regular intervals once it pass a certain size defined in settings.

This commit is contained in:
Griatch 2012-04-28 00:37:36 +02:00
parent e3ce0a7933
commit 3091587e33
8 changed files with 137 additions and 106 deletions

View file

@ -1,17 +1,17 @@
"""
These are actions for the dummy client runner, using
the default command set and intended for unmodified Evennia.
These are actions for the dummy client runner, using
the default command set and intended for unmodified Evennia.
Each client action is defined as a function. The clients
will perform these actions randomly (except the login action).
will perform these actions randomly (except the login action).
Each action-definition function should take one argument- "client",
which is a reference to the client currently performing the action
Use the client object for saving data between actions.
Use the client object for saving data between actions.
The client object has the following relevant properties and methods:
cid - unique client id
istep - the current step
cid - unique client id
istep - the current step
exits - an empty list. Can be used to store exit names
objs - an empty list. Can be used to store object names
counter() - get an integer value. This counts up for every call and
@ -19,7 +19,7 @@ The client object has the following relevant properties and methods:
The action-definition function should return the command that the
client should send to the server (as if it was input in a mud client).
It should also return a string detailing the action taken. This string is
It should also return a string detailing the action taken. This string is
used by the "brief verbose" mode of the runner and is prepended by
"Client N " to produce output like "Client 3 is creating objects ..."
@ -30,10 +30,10 @@ are 2-tuples (probability, action_func), where probability defines how
common it is for that particular action to happen. The runner will
randomly pick between those functions based on the probability.
ACTIONS = (login_func, (0.3, func1), (0.1, func2) ... )
ACTIONS = (login_func, (0.3, func1), (0.1, func2) ... )
To change the runner to use your custom ACTION and/or action
definitions, edit settings.py and add
definitions, edit settings.py and add
DUMMYRUNNER_ACTIONS_MODULE = "path.to.your.module"
@ -45,27 +45,27 @@ definitions, edit settings.py and add
import time
RUNID = time.time()
# some convenient templates
# some convenient templates
START_ROOM = "testing_room_start-%s-%s" % (RUNID, "%i")
START_ROOM = "testing_room_start-%s-%s" % (RUNID, "%i")
ROOM_TEMPLATE = "testing_room_%s-%s" % (RUNID, "%i")
EXIT_TEMPLATE = "exit_%s-%s" % (RUNID, "%i")
OBJ_TEMPLATE = "testing_obj_%s-%s" % (RUNID, "%i")
TOBJ_TEMPLATE = "testing_button_%s-%s" % (RUNID, "%i")
TOBJ_TYPECLASS = "examples.red_button.RedButton"
# action function definitions
# action function definitions
def c_login(client):
"logins to the game"
"logins to the game"
cname = "Dummy-%s-%i" % (RUNID, client.cid)
cemail = "%s@dummy.com" % (cname.lower())
cpwd = "%s-%s" % (RUNID, client.cid)
cmd = ('create "%s" %s %s' % (cname, cemail, cpwd),
cmd = ('create "%s" %s %s' % (cname, cemail, cpwd),
'connect %s %s' % (cemail, cpwd),
'@dig %s' % START_ROOM % client.cid,
'@teleport %s' % START_ROOM % client.cid)
return cmd, "logs in as %s ..." % cname
def c_logout(client):
@ -75,18 +75,18 @@ def c_logout(client):
def c_looks(client):
"looks at various objects"
cmd = ["look %s" % obj for obj in client.objs]
if not cmd:
if not cmd:
cmd = ["look %s" % exi for exi in client.exits]
if not cmd:
if not cmd:
cmd = "look"
return cmd, "looks ..."
def c_examines(client):
"examines various objects"
cmd = ["examine %s" % obj for obj in client.objs]
if not cmd:
if not cmd:
cmd = ["examine %s" % exi for exi in client.exits]
if not cmd:
if not cmd:
cmd = "examine me"
return cmd, "examines objs ..."
@ -96,30 +96,30 @@ def c_help(client):
'help @teleport',
'help look',
'help @tunnel',
'help @dig')
'help @dig')
return cmd, "reads help ..."
def c_digs(client):
"digs a new room, storing exit names on client"
"digs a new room, storing exit names on client"
roomname = ROOM_TEMPLATE % client.counter()
exitname1 = EXIT_TEMPLATE % client.counter()
exitname2 = EXIT_TEMPLATE % client.counter()
client.exits.extend([exitname1, exitname2])
client.exits.extend([exitname1, exitname2])
cmd = '@dig %s = %s, %s' % (roomname, exitname1, exitname2)
return cmd, "digs ..."
def c_creates_obj(client):
"creates normal objects, storing their name on client"
"creates normal objects, storing their name on client"
objname = OBJ_TEMPLATE % client.counter()
client.objs.append(objname)
cmd = ('@create %s' % objname,
'@desc %s = "this is a test object' % objname,
'@set %s/testattr = this is a test attribute value.' % objname,
'@set %s/testattr2 = this is a second test attribute.' % objname)
'@set %s/testattr2 = this is a second test attribute.' % objname)
return cmd, "creates obj ..."
def c_creates_button(client):
"creates example button, storing name on client"
"creates example button, storing name on client"
objname = TOBJ_TEMPLATE % client.counter()
client.objs.append(objname)
cmd = ('@create %s:%s' % (objname, TOBJ_TYPECLASS),
@ -134,21 +134,43 @@ def c_moves(client):
# Action tuple (required)
#
#
# This is a tuple of client action functions. The first element is the
# function the client should use to log into the game and move to
# STARTROOM . The second element is the logout command, for cleanly
# STARTROOM . The second element is the logout command, for cleanly
# exiting the mud. The following elements are 2-tuples of (probability,
# action_function). The probablities should normally sum up to 1,
# otherwise the system will normalize them.
# otherwise the system will normalize them.
#
ACTIONS = ( c_login,
c_logout,
(0.2, c_looks),
(0.1, c_examines),
(0.2, c_help),
(0.1, c_digs),
(0.1, c_creates_obj),
# heavy builder definition
#ACTIONS = ( c_login,
# c_logout,
# (0.2, c_looks),
# (0.1, c_examines),
# (0.2, c_help),
# (0.1, c_digs),
# (0.1, c_creates_obj),
# #(0.1, c_creates_button),
# (0.2, c_moves))
# "normal builder" definition
ACTIONS = ( c_login,
c_logout,
(0.5, c_looks),
(0.08, c_examines),
(0.1, c_help),
(0.01, c_digs),
(0.01, c_creates_obj),
#(0.1, c_creates_button),
(0.2, c_moves))
(0.3, c_moves))
# "normal player" definition
#ACTIONS = ( c_login,
# c_logout,
# (0.4, c_looks),
# #(0.1, c_examines),
# (0.2, c_help),
# #(0.1, c_digs),
# #(0.1, c_creates_obj),
# #(0.1, c_creates_button),
# (0.4, c_moves))

View file

@ -8,7 +8,6 @@ be of use when designing your own game.
"""
from inspect import ismodule
import os, sys, imp, types, math
from collections import Counter
import textwrap
import datetime
import random
@ -460,7 +459,14 @@ def run_async(async_func, at_return=None, at_err=None):
Use this function with restrain and only for features/commands
that you know has no influence on the cause-and-effect order of your
game (commands given after the async function might be executed before
it has finished).
it has finished). Accessing the same property from different threads can
lead to unpredicted behaviour if you are not careful (this is called a
"race condition").
Also note that some databases, notably sqlite3, don't support access from
multiple threads simultaneously, so if you do heavy database access from
your async_func under sqlite3 you will probably run very slow or even get
tracebacks.
async_func() - function that should be run asynchroneously
at_return(r) - if given, this function will be called when async_func returns