Moved get_evennia_pids into src.utils.utils for more general access.
This commit is contained in:
parent
2a7c45d6e8
commit
033344ad2c
5 changed files with 36 additions and 49 deletions
|
|
@ -167,6 +167,7 @@ class CmdUnconnectedCreate(MuxCommand):
|
||||||
|
|
||||||
except Exception, e:
|
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)
|
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
|
return
|
||||||
|
|
||||||
# This needs to be called so the engine knows this player is logging in for the first time.
|
# This needs to be called so the engine knows this player is logging in for the first time.
|
||||||
|
|
|
||||||
|
|
@ -3,31 +3,28 @@ Central caching module.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os, threading
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from django.dispatch import Signal
|
from django.dispatch import Signal
|
||||||
from django.core.cache import get_cache
|
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.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__
|
_GA = object.__getattribute__
|
||||||
_SA = object.__setattr__
|
_SA = object.__setattr__
|
||||||
_DA = object.__delattr__
|
_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 = {}
|
||||||
#_ATTR_CACHE = get_cache("attr_cache")
|
|
||||||
#_PROP_CACHE = get_cache("prop_cache")
|
|
||||||
_PROP_CACHE = defaultdict(dict)
|
_PROP_CACHE = defaultdict(dict)
|
||||||
|
|
||||||
# make sure caches are empty at startup
|
|
||||||
#_FIELD_CACHE.clear()
|
|
||||||
_ATTR_CACHE.clear()
|
|
||||||
#_PROP_CACHE.clear()
|
|
||||||
|
|
||||||
#------------------------------------------------------------
|
#------------------------------------------------------------
|
||||||
# Cache key hash generation
|
# Cache key hash generation
|
||||||
|
|
|
||||||
|
|
@ -160,23 +160,7 @@ DATABASES = {
|
||||||
'HOST':'',
|
'HOST':'',
|
||||||
'PORT':''
|
'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
|
# Evennia pluggable modules
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ from twisted.internet.reactor import callFromThread
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.db.models.base import Model, ModelBase
|
from django.db.models.base import Model, ModelBase
|
||||||
from django.db.models.signals import post_save, pre_delete, post_syncdb
|
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
|
from manager import SharedMemoryManager
|
||||||
|
|
||||||
|
|
@ -28,31 +28,11 @@ _DA = object.__delattr__
|
||||||
# determine if our current pid is different from the server PID (i.e.
|
# determine if our current pid is different from the server PID (i.e.
|
||||||
# if we are in a subprocess or not)
|
# if we are in a subprocess or not)
|
||||||
from src import PROC_MODIFIED_OBJS
|
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
|
# get info about the current process and thread
|
||||||
|
|
||||||
_SELF_PID = os.getpid()
|
_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_SUBPROCESS = (_SERVER_PID and _PORTAL_PID) and not _SELF_PID in (_SERVER_PID, _PORTAL_PID)
|
||||||
_IS_MAIN_THREAD = threading.currentThread().getName() == "MainThread"
|
_IS_MAIN_THREAD = threading.currentThread().getName() == "MainThread"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -899,3 +899,28 @@ def format_table(table, extra_space=1):
|
||||||
for icol, col in enumerate(table)])
|
for icol, col in enumerate(table)])
|
||||||
return ftable
|
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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue