diff --git a/src/commands/default/unloggedin.py b/src/commands/default/unloggedin.py index d9c5145f7c..5485d14132 100644 --- a/src/commands/default/unloggedin.py +++ b/src/commands/default/unloggedin.py @@ -167,6 +167,7 @@ class CmdUnconnectedCreate(MuxCommand): except Exception, e: session.msg("There was an error creating the default Player/Character:\n%s\n If this problem persists, contact an admin." % e) + logger.log_trace() return # This needs to be called so the engine knows this player is logging in for the first time. diff --git a/src/server/caches.py b/src/server/caches.py index 8d36d1f9f8..1fe9eef25d 100644 --- a/src/server/caches.py +++ b/src/server/caches.py @@ -3,31 +3,28 @@ Central caching module. """ +import os, threading from collections import defaultdict from django.dispatch import Signal from django.core.cache import get_cache -#from django.db.models.signals import pre_save, pre_delete, post_init from src.server.models import ServerConfig -from src.utils.utils import uses_database, to_str +from src.utils.utils import uses_database, to_str, get_evennia_pids _GA = object.__getattribute__ _SA = object.__setattr__ _DA = object.__delattr__ +_IS_SUBPROCESS = os.getpid() in get_evennia_pids() +_IS_MAIN_THREAD = threading.currentThread().getName() == "MainThread" + # -# Open handles to the caches +# Set up the cache stores # -#_FIELD_CACHE = get_cache("field_cache") +_FIELD_CACHE = {} _ATTR_CACHE = {} -#_ATTR_CACHE = get_cache("attr_cache") -#_PROP_CACHE = get_cache("prop_cache") _PROP_CACHE = defaultdict(dict) -# make sure caches are empty at startup -#_FIELD_CACHE.clear() -_ATTR_CACHE.clear() -#_PROP_CACHE.clear() #------------------------------------------------------------ # Cache key hash generation diff --git a/src/settings_default.py b/src/settings_default.py index e055f5c66e..86bd81da09 100644 --- a/src/settings_default.py +++ b/src/settings_default.py @@ -160,23 +160,7 @@ DATABASES = { 'HOST':'', 'PORT':'' }} -# This manages the object-level caches. Evennia will agressively cache -# fields, properties and attribute lookup. Evennia uses a fast and -# local in-memory cache by default. If a Memcached server is available -# it can be used instead (see django docs). Cache performance can be -# tweaked by adding options to each cache. Finally, any cache can -# be completely turned off by pointing its backend -# to 'django.core.cache.backends.dummy.DummyCache'. -CACHES = { - 'default': { - 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}, - 'field_cache': { - 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}, - 'prop_cache': { - 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}, - 'attr_cache': { - 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}, - } + ###################################################################### # Evennia pluggable modules ###################################################################### diff --git a/src/utils/idmapper/base.py b/src/utils/idmapper/base.py index 73412f8c70..2b4e6ce460 100755 --- a/src/utils/idmapper/base.py +++ b/src/utils/idmapper/base.py @@ -14,7 +14,7 @@ from twisted.internet.reactor import callFromThread from django.core.exceptions import ObjectDoesNotExist from django.db.models.base import Model, ModelBase from django.db.models.signals import post_save, pre_delete, post_syncdb -from src.utils.utils import dbref +from src.utils.utils import dbref, get_evennia_pids from manager import SharedMemoryManager @@ -28,31 +28,11 @@ _DA = object.__delattr__ # determine if our current pid is different from the server PID (i.e. # if we are in a subprocess or not) from src import PROC_MODIFIED_OBJS -def _get_pids(): - """ - Get the PID (Process ID) by trying to access - an PID file. - """ - from django.conf import settings - server_pidfile = os.path.join(settings.GAME_DIR, 'server.pid') - portal_pidfile = os.path.join(settings.GAME_DIR, 'portal.pid') - server_pid, portal_pid = None, None - if os.path.exists(server_pidfile): - f = open(server_pidfile, 'r') - server_pid = f.read() - f.close() - if os.path.exists(portal_pidfile): - f = open(portal_pidfile, 'r') - portal_pid = f.read() - f.close() - if server_pid and portal_pid: - return int(server_pid), int(portal_pid) - return None, None # get info about the current process and thread _SELF_PID = os.getpid() -_SERVER_PID, _PORTAL_PID = _get_pids() +_SERVER_PID, _PORTAL_PID = get_evennia_pids() _IS_SUBPROCESS = (_SERVER_PID and _PORTAL_PID) and not _SELF_PID in (_SERVER_PID, _PORTAL_PID) _IS_MAIN_THREAD = threading.currentThread().getName() == "MainThread" diff --git a/src/utils/utils.py b/src/utils/utils.py index 75b52b89ea..c072c36002 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -899,3 +899,28 @@ def format_table(table, extra_space=1): for icol, col in enumerate(table)]) return ftable +def get_evennia_pids(): + """ + Get the currently valids PIDs (Process IDs) of the Portal and Server + by trying to access an PID file. This can be used to determine if we + are in a subprocess by something like + + self_pid = os.getpid() + server_pid, portal_pid = get_evennia_pids() + is_subprocess = self_pid not in (server_pid, portal_pid) + + """ + server_pidfile = os.path.join(settings.GAME_DIR, 'server.pid') + portal_pidfile = os.path.join(settings.GAME_DIR, 'portal.pid') + server_pid, portal_pid = None, None + if os.path.exists(server_pidfile): + f = open(server_pidfile, 'r') + server_pid = f.read() + f.close() + if os.path.exists(portal_pidfile): + f = open(portal_pidfile, 'r') + portal_pid = f.read() + f.close() + if server_pid and portal_pid: + return int(server_pid), int(portal_pid) + return None, None