def run(self, py_file): self.py_file = py_file #use the current executing version of IPY to launch the debug process ipy = Assembly.GetEntryAssembly().Location cmd_line = "\"%s\" -D \"%s\"" % (ipy, py_file) self.process = self.debugger.CreateProcess(ipy, cmd_line) self.process.OnCreateAppDomain += self.OnCreateAppDomain self.process.OnProcessExit += self.OnProcessExit self.process.OnUpdateModuleSymbols += self.OnUpdateModuleSymbols self.process.OnBreakpoint += self.OnBreakpoint self.process.OnStepComplete += self.OnStepComplete self.process.OnClassLoad += self.OnClassLoad self.terminate_event = AutoResetEvent(False) self.break_event = AutoResetEvent(False) self.initial_breakpoint = None self.breakpoints = [] self.source_files = dict() handles = Array.CreateInstance(WaitHandle, 2) handles[0] = self.terminate_event handles[1] = self.break_event while True: if hasattr(self, 'active_thread'): delattr(self, 'active_thread') if hasattr(self, 'active_appdomain'): delattr(self, 'active_appdomain') self.process.Continue(False) i = WaitHandle.WaitAny(handles) if i == 0: break self._input()
def startInteractive(): global are are = AutoResetEvent(False) t = Thread(ThreadStart(appStart)) t.ApartmentState = ApartmentState.STA t.Start() are.WaitOne() IronPython.Hosting.PythonEngine.ConsoleCommandDispatcher = DispatchConsoleCommand
def __init__(self): logger.debug('Here we go') self.auto = Automation(True, List[String]()) self.application = self.auto.LightFieldApplication self.experiment = self.application.Experiment self.file_manager = self.application.FileManager self.acquireCompleted = AutoResetEvent(False) self.dataset = Dataset() time.sleep(3) logger.debug('Loaded')
global called, globalSelf, globalArg called = True globalSelf = self globalArg = arg if is_cli: import clr if is_netcoreapp: clr.AddReference("System.Threading.Thread") from System import EventArgs from System.Threading import AutoResetEvent are = AutoResetEvent(False) @skipUnlessIronPython() class DelegateTest(IronPythonTestCase): def setUp(self): super(DelegateTest, self).setUp() global selph self.load_iron_python_test() import IronPythonTest selph = self def test_SimpleHandler(self): import IronPythonTest dlgTst = IronPythonTest.DelegateTest()
# Create the LightField Application (true for visible) # The 2nd parameter forces LF to load with no experiment auto = Automation(True, List[String]()) # Get LightField Application object application = auto.LightFieldApplication # Get experiment object experiment = application.Experiment # Get file manager object file_manager = application.FileManager # Notifies a waiting thread that an event has occurred acquireCompleted = AutoResetEvent(False) # Check for device and inform user if one is needed if (device_found() == True): # Hook the experiment completed handler experiment.ExperimentCompleted += experiment_completed try: # Acquire image in LightField experiment.Acquire() # Wait for acquisition to complete acquireCompleted.WaitOne() finally: # Cleanup handler
def testMultipleSaveRestoreMultiThread(self, mapper, _): # order of execution (intended) mapper.ReleaseGIL() lock = GetGIL(mapper) oneThreadActed = AutoResetEvent(False) anotherThreadActed = AutoResetEvent(False) def OneThread(): wait = lambda: anotherThreadActed.WaitOne() signal = lambda: oneThreadActed.Set() mapper.PyGILState_Ensure() # 1 signal() wait() pe_token = mapper.PyEval_SaveThread() # 3 self.assertNotEquals(pe_token, IntPtr.Zero) signal() wait() self.assertFalse(lock.TryAcquire()) # 5 signal() wait() self.assertTrue(lock.TryAcquire()) # 7 lock.Release() signal() wait() self.assertTrue(lock.TryAcquire()) # 9 lock.Release() signal() wait() self.assertTrue(lock.TryAcquire()) # 11 lock.Release() signal() wait() self.assertFalse(lock.TryAcquire()) # 13 signal() wait() mapper.PyEval_RestoreThread(pe_token) # 15 signal() wait() mapper.PyGILState_Release(0) # 17 def AnotherThread(): wait = lambda: oneThreadActed.WaitOne() signal = lambda: anotherThreadActed.Set() wait() self.assertFalse(lock.TryAcquire()) # 2 signal() wait() mapper.PyGILState_Ensure() # 4 signal() wait() pe_token = mapper.PyEval_SaveThread() # 6 self.assertNotEquals(pe_token, IntPtr.Zero) signal() wait() x = mapper.PyEval_SaveThread() # 8 self.assertEquals(x, IntPtr.Zero) signal() wait() mapper.PyEval_RestoreThread(x) # 10 signal() wait() mapper.PyEval_RestoreThread(pe_token) # 12 signal() wait() mapper.PyGILState_Release(0) # 14 signal() wait() self.assertFalse(lock.TryAcquire()) # 16 signal() t = Thread(ThreadStart(AnotherThread)) t.Start() OneThread() t.Join() mapper.EnsureGIL()
import Apollo.Core.Base import Apollo.Core.Base.Activation import Apollo.Core.Scripting from System.Diagnostics import Process from System.Management import (ManagementObject, ManagementObjectSearcher) from System.Threading import AutoResetEvent from Apollo.Core.Base.Activation import DistributionLocations from Apollo.Core.Scripting.Projects import DistributionSuggestionProxy def SelectFrom(options): return options[0] activateevent = AutoResetEvent(False) def switchonactivate(sender, eventargs): activateevent.Set() deactivateevent = AutoResetEvent(False) def switchondeactivate(sender, eventargs): deactivateevent.Set() # Verify that we don't have an active project hasactiveproject = projects.HasActiveProject()