From 12523c81b61c9a9850e815073b402de6e8fcca9f Mon Sep 17 00:00:00 2001 From: Griatch Date: Mon, 3 Sep 2012 21:33:03 +0200 Subject: [PATCH] Some fixes for using evlang without ProcPool. --- contrib/evlang/evlang.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/contrib/evlang/evlang.py b/contrib/evlang/evlang.py index d5d068391..b1e91d7df 100644 --- a/contrib/evlang/evlang.py +++ b/contrib/evlang/evlang.py @@ -85,6 +85,8 @@ from django.core.management import setup_environ from game import settings setup_environ(settings) from src.utils.utils import run_async + +_PROCPOOL_ENABLED = settings.PROCPOOL_ENABLED _LOGGER = None #------------------------------------------------------------ @@ -828,17 +830,18 @@ def limited_exec(code, context = {}, timeout_secs=2, retobj=None): if code did not execute within the given timelimit = LimitedExecTimeoutException """ - if retobj: - callback = lambda r: retobj.msg(r) - errback = lambda e: retobj.msg(e) + if validate_context(context) and validate_code(code): # run code only after validation has completed - if validate_context(context) and validate_code(code): - run_async(code, *context, proc_timeout=timeout_secs, at_return=callback, at_err=errback) - else: - # run code only after validation has completed - if validate_context(context) and validate_code(code): - run_async(code, *context) - + if _PROCPOOL_ENABLED: + if retobj: + callback = lambda r: retobj.msg(r) + errback = lambda e: retobj.msg(e) + run_async(code, *context, proc_timeout=timeout_secs, at_return=callback, at_err=errback) + else: + run_async(code, *context, proc_timeout=timeout_secs) + else: + # run in-process + exec code in context #----------------------------------------------------------------------