Changed contrib/procpool's PROC_MODIFIED_OBJS list to sit in src.utils.idmapper.base as well as be a WeakValueDictionary instead of a normal list. This removes unnecessary reference counts to objects.
This commit is contained in:
parent
cdc071981d
commit
87d1254b2c
3 changed files with 13 additions and 10 deletions
|
|
@ -32,9 +32,9 @@ from twisted.protocols import amp
|
||||||
from twisted.internet import threads
|
from twisted.internet import threads
|
||||||
from contrib.procpools.ampoule.child import AMPChild
|
from contrib.procpools.ampoule.child import AMPChild
|
||||||
from src.utils.dbserialize import to_pickle, from_pickle, do_pickle, do_unpickle
|
from src.utils.dbserialize import to_pickle, from_pickle, do_pickle, do_unpickle
|
||||||
|
from src.utils.idmapper.base import PROC_MODIFIED_OBJS
|
||||||
from src.utils.utils import clean_object_caches, to_str
|
from src.utils.utils import clean_object_caches, to_str
|
||||||
from src.utils import logger
|
from src.utils import logger
|
||||||
from src import PROC_MODIFIED_OBJS
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
@ -140,7 +140,7 @@ class PythonProcPoolChild(AMPChild):
|
||||||
exec source in available_vars
|
exec source in available_vars
|
||||||
ret = _return.get_returns()
|
ret = _return.get_returns()
|
||||||
# get the list of affected objects to recache
|
# get the list of affected objects to recache
|
||||||
objs = list(set(PROC_MODIFIED_OBJS))
|
objs = PROC_MODIFIED_OBJS.values()
|
||||||
# we need to include the locations too, to update their content caches
|
# we need to include the locations too, to update their content caches
|
||||||
objs = objs + list(set([o.location for o in objs
|
objs = objs + list(set([o.location for o in objs
|
||||||
if hasattr(o, "location") and o.location]))
|
if hasattr(o, "location") and o.location]))
|
||||||
|
|
@ -151,7 +151,8 @@ class PythonProcPoolChild(AMPChild):
|
||||||
else:
|
else:
|
||||||
to_recache = ""
|
to_recache = ""
|
||||||
# empty the list without loosing memory reference
|
# empty the list without loosing memory reference
|
||||||
PROC_MODIFIED_OBJS[:] = []
|
#PROC_MODIFIED_OBJS[:] = []
|
||||||
|
PROC_MODIFIED_OBJS.clear() #TODO - is this not messing anything up?
|
||||||
return {'response': ret,
|
return {'response': ret,
|
||||||
'recached': to_recache}
|
'recached': to_recache}
|
||||||
ExecuteCode.responder(executecode)
|
ExecuteCode.responder(executecode)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
# experimental central dictionary for models in
|
|
||||||
# subprocesses to report they have been changed.
|
|
||||||
PROC_MODIFIED_OBJS = []
|
|
||||||
|
|
@ -25,10 +25,11 @@ _GA = object.__getattribute__
|
||||||
_SA = object.__setattr__
|
_SA = object.__setattr__
|
||||||
_DA = object.__delattr__
|
_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); Changes are stored here so the
|
||||||
from src import PROC_MODIFIED_OBJS
|
# main process can be informed to update itself.
|
||||||
|
PROC_MODIFIED_COUNT = 0
|
||||||
|
PROC_MODIFIED_OBJS = WeakValueDictionary()
|
||||||
|
|
||||||
# get info about the current process and thread
|
# get info about the current process and thread
|
||||||
_SELF_PID = os.getpid()
|
_SELF_PID = os.getpid()
|
||||||
|
|
@ -36,6 +37,8 @@ _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"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#_SERVER_PID = None
|
#_SERVER_PID = None
|
||||||
#_PORTAL_PID = None
|
#_PORTAL_PID = None
|
||||||
# #global _SERVER_PID, _PORTAL_PID, _IS_SUBPROCESS, _SELF_PID
|
# #global _SERVER_PID, _PORTAL_PID, _IS_SUBPROCESS, _SELF_PID
|
||||||
|
|
@ -259,7 +262,9 @@ class SharedMemoryModel(Model):
|
||||||
if _IS_SUBPROCESS:
|
if _IS_SUBPROCESS:
|
||||||
# we keep a store of objects modified in subprocesses so
|
# we keep a store of objects modified in subprocesses so
|
||||||
# we know to update their caches in the central process
|
# we know to update their caches in the central process
|
||||||
PROC_MODIFIED_OBJS.append(cls)
|
global PROC_MODIFIED_COUNT, PROC_MODIFIED_OBJS
|
||||||
|
PROC_MODIFIED_COUNT += 1
|
||||||
|
PROC_MODIFIED_OBJS[PROC_MODIFIED_COUNT] = cls
|
||||||
|
|
||||||
if _IS_MAIN_THREAD:
|
if _IS_MAIN_THREAD:
|
||||||
# in main thread - normal operation
|
# in main thread - normal operation
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue