tags:

views:

55

answers:

0

Hi everyone, I am currently using twisted with wsgi. I wrote my own Engine class which powers the backend to all the logic in my application. Is there an easier method that would allow me to do the following?

in run.py

#Django setup
sys.path.append("spontivity_web")
os.environ['DJANGO_SETTINGS_MODULE'] = 'spontivity_web.settings'
from django.core.handlers.wsgi import WSGIHandler

myEngine = Engine()  # <-- this is my game engine

def wsgi_resource():
    pool = threadpool.ThreadPool()
    pool.start()
    # Allow Ctrl-C to get you out cleanly:
    reactor.addSystemEventTrigger('after', 'shutdown', pool.stop)
    wsgi_resource = wsgi.WSGIResource(reactor, pool, WSGIHandler())
    return wsgi_resource

wsgi_root = wsgi_resource()
reactor.listenTCP(DJANGO_PORT, server.Site(wsgi_root))
reactor.listenTCP(XMLRPC_PORT, server.Site(xmlrpc_server))

in one of my views.py inside django

@login_required
    if request.method == "POST":
        user_hexid = request.session['user_hexid']
        room_hexid = request.POST['room_hexid']
        xmlrpc_engine.attack_person( user_hexid, target_hexid)
        # Ideally I want to run 
        # smuggledEngine.attack_person ....
        return HttpResponse("OK")

I was wondering whether I can do away with xmlrpc completely by smuggling the instance of engine into the WSGI environment.

Note that my engine has to be singleton and there should only be one instance as it controls all the logic to my game.