def run(rootScriptPathDir,configFilePath): import tempfile tdir=tempfile.gettempdir() cdir,cfile=os.path.split(configFilePath) if tdir==cdir: tf=open(configFilePath) ioHubConfig=json.loads(tf.read()) tf.close() os.remove(configFilePath) else: ioHubConfig=load(file(configFilePath,'r'), Loader=Loader) hub_defaults_config=load(file(os.path.join(iohub.IO_HUB_DIRECTORY,'default_config.yaml'),'r'), Loader=Loader) updateDict(ioHubConfig,hub_defaults_config) try: s = ioServer(rootScriptPathDir, ioHubConfig) except Exception,e: printExceptionDetailsToStdErr() sys.stdout.flush() try: s.shutdown() except: pass return -1
def run(rootScriptPathDir, configFilePath): import tempfile tdir = tempfile.gettempdir() cdir, cfile = os.path.split(configFilePath) if tdir == cdir: tf = open(configFilePath) ioHubConfig = json.loads(tf.read()) tf.close() os.remove(configFilePath) else: ioHubConfig = load(file(configFilePath, 'r'), Loader=Loader) hub_defaults_config = load(file( os.path.join(iohub.IO_HUB_DIRECTORY, 'default_config.yaml'), 'r'), Loader=Loader) updateDict(ioHubConfig, hub_defaults_config) try: s = ioServer(rootScriptPathDir, ioHubConfig) except Exception, e: printExceptionDetailsToStdErr() sys.stdout.flush() try: s.shutdown() except: pass return -1
def run(rootScriptPathDir, configFilePath): s = None try: psychopy.iohub.EXP_SCRIPT_DIRECTORY = rootScriptPathDir tdir = tempfile.gettempdir() cdir, _ = os.path.split(configFilePath) if tdir == cdir: tf = open(configFilePath) ioHubConfig = json.loads(tf.read()) tf.close() os.remove(configFilePath) else: ioHubConfig = yload(open(configFilePath, 'r'), Loader=yLoader) hub_config_path = os.path.join(IOHUB_DIRECTORY, 'default_config.yaml') hub_defaults_config = yload(open(hub_config_path, 'r'), Loader=yLoader) updateDict(ioHubConfig, hub_defaults_config) s = ioServer(rootScriptPathDir, ioHubConfig) udp_port = s.config.get('udp_port', 9000) s.log("Receiving diagram's on: {}".format(udp_port)) s.udpService.start() s.setStatus("INITIALIZING") msgpump_interval = s.config.get('msgpump_interval', 0.001) glets = [] tlet = gevent.spawn(s.pumpMsgTasklet, msgpump_interval) glets.append(tlet) for m in s.deviceMonitors: m.start() glets.append(m) tlet = gevent.spawn(s.processEventsTasklet, 0.01) glets.append(tlet) if Computer.psychopy_process: tlet = gevent.spawn(s.checkForPsychopyProcess, 0.5) glets.append(tlet) s.setStatus("RUNNING") if hasattr(gevent, 'run'): gevent.run() glets = [] else: gevent.joinall(glets) lrtime = Computer.global_clock.getLastResetTime() s.log('Server END Time Offset: {0}'.format(lrtime), 'DEBUG') return True except Exception: # pylint: disable=broad-except printExceptionDetailsToStdErr() if s: s.shutdown() return False
def run(rootScriptPathDir,configFilePath): psychopy.iohub.EXP_SCRIPT_DIRECTORY = rootScriptPathDir import tempfile tdir=tempfile.gettempdir() cdir,cfile=os.path.split(configFilePath) if tdir==cdir: tf=open(configFilePath) ioHubConfig=json.loads(tf.read()) tf.close() os.remove(configFilePath) else: ioHubConfig=load(file(configFilePath,'r'), Loader=Loader) hub_defaults_config=load(file(os.path.join(psychopy.iohub.IO_HUB_DIRECTORY,'default_config.yaml'),'r'), Loader=Loader) updateDict(ioHubConfig,hub_defaults_config) try: s = ioServer(rootScriptPathDir, ioHubConfig) except Exception as e: printExceptionDetailsToStdErr() sys.stdout.flush() try: s.shutdown() except Exception: pass return -1 try: s.log('Receiving datagrams on :9000') s.udpService.start() if Computer.system == 'win32': gevent.spawn(s.pumpMsgTasklet, s.config.get('windows_msgpump_interval', 0.00375)) if hasattr(gevent,'run'): for m in s.deviceMonitors: m.start() gevent.spawn(s.processEventsTasklet, 0.01) sys.stdout.write("IOHUB_READY\n\r\n\r") #print2err("Computer.psychopy_process: ", Computer.psychopy_process) if Computer.psychopy_process: gevent.spawn(s.checkForPsychopyProcess, 0.5) sys.stdout.flush() gevent.run() else: glets=[] if Computer.system == 'win32': glets.append(gevent.spawn(s.pumpMsgTasklet, s.config.get('windows_msgpump_interval', 0.00375))) for m in s.deviceMonitors: m.start() glets.append(m) glets.append(gevent.spawn(s.processEventsTasklet,0.01)) sys.stdout.write("IOHUB_READY\n\r\n\r") sys.stdout.flush() #print2err("Computer.psychopy_process: ", Computer.psychopy_process) if Computer.psychopy_process: glets.append(gevent.spawn(s.checkForPsychopyProcess, 0.5)) gevent.joinall(glets) s.log("Server END Time Offset: {0}".format(Computer.global_clock.getLastResetTime()),'DEBUG') except Exception as e: print2err("Error occurred during ioServer.start(): ",str(e)) printExceptionDetailsToStdErr() print2err("------------------------------") sys.stdout.write("IOHUB_FAILED\n\r\n\r") sys.stdout.flush() try: s.shutdown() except Exception: pass return -1
def run(rootScriptPathDir,configFilePath): psychopy.iohub.EXP_SCRIPT_DIRECTORY = rootScriptPathDir import tempfile tdir=tempfile.gettempdir() cdir,cfile=os.path.split(configFilePath) if tdir==cdir: tf=open(configFilePath) ioHubConfig=json.loads(tf.read()) tf.close() os.remove(configFilePath) else: ioHubConfig=load(open(configFilePath,'r'), Loader=Loader) hub_defaults_config=load(open(os.path.join(psychopy.iohub.IO_HUB_DIRECTORY,'default_config.yaml'),'r'), Loader=Loader) updateDict(ioHubConfig,hub_defaults_config) try: s = ioServer(rootScriptPathDir, ioHubConfig) except Exception as e: printExceptionDetailsToStdErr() sys.stdout.flush() try: s.shutdown() except Exception: pass return -1 try: s.log('Receiving datagrams on :9000') s.udpService.start() if Computer.system == 'win32': gevent.spawn(s.pumpMsgTasklet, s.config.get('windows_msgpump_interval', 0.00375)) if hasattr(gevent,'run'): for m in s.deviceMonitors: m.start() gevent.spawn(s.processEventsTasklet, 0.01) sys.stdout.write("IOHUB_READY\n\r\n\r") #print2err("Computer.psychopy_process: ", Computer.psychopy_process) if Computer.psychopy_process: gevent.spawn(s.checkForPsychopyProcess, 0.5) sys.stdout.flush() gevent.run() else: glets=[] if Computer.system == 'win32': glets.append(gevent.spawn(s.pumpMsgTasklet, s.config.get('windows_msgpump_interval', 0.00375))) for m in s.deviceMonitors: m.start() glets.append(m) glets.append(gevent.spawn(s.processEventsTasklet,0.01)) sys.stdout.write("IOHUB_READY\n\r\n\r") sys.stdout.flush() #print2err("Computer.psychopy_process: ", Computer.psychopy_process) if Computer.psychopy_process: glets.append(gevent.spawn(s.checkForPsychopyProcess, 0.5)) gevent.joinall(glets) s.log("Server END Time Offset: {0}".format(Computer.global_clock.getLastResetTime()),'DEBUG') except Exception as e: print2err("Error occurred during ioServer.start(): ",str(e)) printExceptionDetailsToStdErr() print2err("------------------------------") sys.stdout.write("IOHUB_FAILED\n\r\n\r") sys.stdout.flush() try: s.shutdown() except Exception: pass return -1