def default_mqs(debug={}, nokill=False, extra=None, **kwargs): global mqs if not isinstance(mqs, meqserver): # create a local tcp port gwlocal = "=meqbatch-%d" % os.getpid() # start octopussy if needed if not octopussy.is_initialized(): octopussy.init(gwclient=False, gwtcp=0, gwlocal=gwlocal + ":1") if not octopussy.is_running(): octopussy.start(wait=True) # start meqserver, overriding default args with any kwargs args = record(**app_defaults.args) args.update(kwargs) # add gwpeer= argument if isinstance(extra, str): extra = args.extra + extra.split(' ') extra = (extra or []) + ["-gw", gwlocal] spawn = args.get('spawn', None) mqs = meqserver(extra=extra, **args) mqs.dprint(1, 'default meqserver args:', args) meqds.set_meqserver(mqs) if not nokill: atexit.register(stop_default_mqs) if debug is None: pass else: octopussy.set_debug(app_defaults.debuglevels) if isinstance(debug, dict): octopussy.set_debug(debug) return mqs
def default_mqs (debug={},nokill=False,extra=None,**kwargs): global mqs; if not isinstance(mqs,meqserver): # create a local tcp port gwlocal = "=meqbatch-%d"%os.getpid(); # start octopussy if needed if not octopussy.is_initialized(): octopussy.init(gwclient=False,gwtcp=0,gwlocal=gwlocal+":1"); if not octopussy.is_running(): octopussy.start(wait=True); # start meqserver, overriding default args with any kwargs args = record(**app_defaults.args); args.update(kwargs); # add gwpeer= argument if isinstance(extra,str): extra = args.extra + extra.split(' '); extra = (extra or []) + ["-gw",gwlocal]; spawn = args.get('spawn',None); mqs = meqserver(extra=extra,**args); mqs.dprint(1,'default meqserver args:',args); meqds.set_meqserver(mqs); if not nokill: atexit.register(stop_default_mqs); if debug is None: pass; else: octopussy.set_debug(app_defaults.debuglevels); if isinstance(debug,dict): octopussy.set_debug(debug); return mqs;
def meqbrowse(debug={}, **kwargs): args = dict(app_defaults.args) args['spawn'] = False for d, l in debug.iteritems(): debuglevels[d] = max(debuglevels.get(d, 0), l) # insert '' into sys.path, so that CWD is always in the search path sys.path.insert(1, '') if debuglevels: octopussy.set_debug(debuglevels) # start octopussy if needed port = options.port sock = options.socket if sock == "None" or sock == "none": sock = "" print "Not binding to a local socket." else: # Use abstract socket on Linux and corresponding file-based socket elsewhere sock = "=" + sock if not sys.platform.startswith('linux'): sock = "/tmp/" + sock print "Binding to local socket %s" % sock # check local socket sk = socket.socket(socket.AF_UNIX) try: sk.bind(("\0" + sock[1:]) if sock[0] == '=' else sock) except: print "Error binding to local socket %s" % sock print "This probably means that another meqbrowser is already running." print "For advanced use, see the -s option (use -h to get help)." sys.exit(1) sk.close() if sock[0] != '=' and os.path.exists(sock): os.remove(sock) print "Binding to TCP port %d, remote meqservers may connect with gwpeer=<host>:%d" % ( port, port) if not octopussy.is_initialized(): octopussy.init(gwclient=False, gwtcp=port, gwlocal=sock) if not octopussy.is_running(): octopussy.start(wait=True) # start meqserver # print "starting meqserver" args['gui'] = True mqs = meqserver.meqserver(**args) # try: # import psyco # psyco.log('psyco.log'); # psyco.profile(); # print "****** psyco enabled."; # except: # print "****** You do not have the psyco package installed."; # print "****** Proceeding anyway, things will run some what slower."; # pass; mqs.run_gui() mqs.disconnect() octopussy.stop()
def meqbrowse (debug={},**kwargs): args = dict(app_defaults.args); args['spawn'] = False; for d,l in debug.iteritems(): debuglevels[d] = max(debuglevels.get(d,0),l); # insert '' into sys.path, so that CWD is always in the search path sys.path.insert(1,''); if debuglevels: octopussy.set_debug(debuglevels); # start octopussy if needed port = options.port; sock = options.socket; if sock == "None" or sock == "none": sock = ""; print "Not binding to a local socket."; else: # Use abstract socket on Linux and corresponding file-based socket elsewhere sock = "="+sock; if not sys.platform.startswith('linux'): sock = "/tmp/"+sock; print "Binding to local socket %s"%sock; # check local socket sk = socket.socket(socket.AF_UNIX); try: sk.bind( ("\0"+sock[1:]) if sock[0] == '=' else sock); except: print "Error binding to local socket %s"%sock; print "This probably means that another meqbrowser is already running." print "For advanced use, see the -s option (use -h to get help)."; sys.exit(1); sk.close(); if sock[0] != '=' and os.path.exists(sock): os.remove(sock) print "Binding to TCP port %d, remote meqservers may connect with gwpeer=<host>:%d"%(port,port); if not octopussy.is_initialized(): octopussy.init(gwclient=False,gwtcp=port,gwlocal=sock); if not octopussy.is_running(): octopussy.start(wait=True); # start meqserver # print "starting meqserver" args['gui'] = True; mqs = meqserver.meqserver(**args); # try: # import psyco # psyco.log('psyco.log'); # psyco.profile(); # print "****** psyco enabled."; # except: # print "****** You do not have the psyco package installed."; # print "****** Proceeding anyway, things will run some what slower."; # pass; mqs.run_gui(); mqs.disconnect(); octopussy.stop();
def main (): for optstr in (options.debug or []): opt = optstr.split("=") + ['1']; context,level = opt[:2]; debuglevels[context] = int(level); Timba.utils.verbosity.disable_argv(); # tell verbosity class to not parse its argv for optstr in (options.verbose or []): opt = optstr.split("=") + ['1']; context,level = opt[:2]; Timba.utils.verbosity.set_verbosity_level(context,level); if not args: parser.print_help(); sys.exit(1); if debuglevels: octopussy.set_debug(debuglevels); script = args[0]; tdljob = (len(args)>1 and args[1]) or None; from Timba.Apps import meqserver from Timba.TDL import Compile from Timba.TDL import TDLOptions # this starts a kernel. if options.compile_only: mqs = None; else: mqs = meqserver.default_mqs(wait_init=10,extra=["-mt",options.mt]); TDLOptions.config.read(options.config); TDLOptions.init_options(script); print "************************ Compiling TDL script",script; # this compiles a script as a TDL module. Any errors will be thrown as # and exception, so this always returns successfully (mod,ns,msg) = Compile.compile_file(mqs,script); if options.compile_only: print msg; sys.exit(0); # if a solve job is not specified, try to find one if tdljob: jobfunc = getattr(mod,tdljob,None); if not jobfunc: print "Cannot find TDL job named",tdljob; sys.exit(1); else: # does the script define an explicit job list? joblist = getattr(mod,'_tdl_job_list',[]); if not joblist: joblist = []; # try to build it from implicit function names for (name,func) in mod.__dict__.iteritems(): if name.startswith("_tdl_job_") and callable(func): joblist.append(func); # does the script define a testing function? testfunc = getattr(mod,'_test_forest',None); if testfunc: joblist.insert(0,testfunc); if not joblist: print "No TDL jobs found in script",script; sys.exit(1); jobfunc = joblist[0]; tdljob = jobfunc.__name__; # this runs the appropriate job. wait=True is needed to wait print "************************ Running TDL job",tdljob; # check if job takes a "wait" argument (fargs,fvarargs,fvarkw,fdefaults) = inspect.getargspec(jobfunc); if 'wait' in fargs or fvarkw: jobopts = dict(wait=True); else: jobopts = {}; jobfunc(mqs,None,**jobopts);
def main(): for optstr in (options.debug or []): opt = optstr.split("=") + ['1'] context, level = opt[:2] debuglevels[context] = int(level) Timba.utils.verbosity.disable_argv() # tell verbosity class to not parse its argv for optstr in (options.verbose or []): opt = optstr.split("=") + ['1'] context, level = opt[:2] Timba.utils.verbosity.set_verbosity_level(context, level) if not args: parser.print_help() sys.exit(1) if debuglevels: octopussy.set_debug(debuglevels) script = args[0] tdljob = (len(args) > 1 and args[1]) or None from Timba.Apps import meqserver from Timba.TDL import Compile from Timba.TDL import TDLOptions # this starts a kernel. if options.compile_only: mqs = None else: mqs = meqserver.default_mqs(wait_init=10, extra=["-mt", options.mt]) TDLOptions.config.read(options.config) TDLOptions.init_options(script) print(("************************ Compiling TDL script", script)) # this compiles a script as a TDL module. Any errors will be thrown as # and exception, so this always returns successfully (mod, ns, msg) = Compile.compile_file(mqs, script) if options.compile_only: print(msg) sys.exit(0) # if a solve job is not specified, try to find one if tdljob: jobfunc = getattr(mod, tdljob, None) if not jobfunc: print(("Cannot find TDL job named", tdljob)) sys.exit(1) else: # does the script define an explicit job list? joblist = getattr(mod, '_tdl_job_list', []) if not joblist: joblist = [] # try to build it from implicit function names for (name, func) in list(mod.__dict__.items()): if name.startswith("_tdl_job_") and callable(func): joblist.append(func) # does the script define a testing function? testfunc = getattr(mod, '_test_forest', None) if testfunc: joblist.insert(0, testfunc) if not joblist: print(("No TDL jobs found in script", script)) sys.exit(1) jobfunc = joblist[0] tdljob = jobfunc.__name__ # this runs the appropriate job. wait=True is needed to wait print(("************************ Running TDL job", tdljob)) # check if job takes a "wait" argument (fargs, fvarargs, fvarkw, fdefaults) = inspect.getargspec(jobfunc) if 'wait' in fargs or fvarkw: jobopts = dict(wait=True) else: jobopts = {} jobfunc(mqs, None, **jobopts)