def main(): """main function for AI console application""" # handle = win32console.GetStdHandle(win32console.STD_INPUT_HANDLE) try: if handle.GetConsoleMode(): pipeOut("MESSAGE Gomoku AI should not be started directly. Please install gomoku manager (http://sourceforge.net/projects/piskvork). Then enter path to this exe file in players settings.") except pywintypes.error: pass # global event1, event2 event1 = win32event.CreateEvent(None, 0, 0, None) win32process.beginthreadex(None, 0, threadLoop, (), 0) event2 = win32event.CreateEvent(None, 1, 1, None) while True: cmd = get_line() do_command(cmd)
def Demo(prog_id): # First create the object object = Dispatch(prog_id) print "Thread", GetCurrentThreadId(), "creating object" created_id = object.GetCreatedThreadId() print "Object reports it was created on thread", created_id # Now create the threads, remembering the handles. handles = [] for i in range(3): # Multi-threaded - just pass the objects directly to the thread. args = (object, ) handle, id = beginthreadex(None, 0, WorkerThread, args, 0) handles.append(handle) # Now we have all the threads running, wait for them to terminate. # No need for message pump, so we can simply wait for all objects # in one call. rc = WaitForMultipleObjects(handles, 1, 5000) if rc == WAIT_ABANDONED: print "Gave up waiting for the threads to finish!" print "Demo of", prog_id, "finished."
def onKeyboardEvent(self, event): if event.Key == 'F9': thread.start_new_thread(self.change_argv, ()) if event.Key == 'F10': if self.suspended: print "Press F10 to pause." win32process.ResumeThread(self.handle) self.suspended = False else: print "Press F10 to continue." win32process.SuspendThread(self.handle) self.suspended = True if event.Key == 'F8': win32api.PostThreadMessage(win32api.GetCurrentThreadId(), win32con.WM_QUIT, 0, 0) if event.Key == 'F12': print 'killed thread' self.suspended = False terminate_thread(int(self.tid)) self.handle, self.tid = win32process.beginthreadex( None, 0, self.main, (), 0) return True
def __init__(self): self.server = Server() thread.start_new_thread(self.server.start, ()) self.suspended = False self.new_argv = '' self.flash_cond = config['exp_flash_cond'] self.team_need_flash = -1 self.mission = 'exp' if len(sys.argv) > 1: self.mission = sys.argv[1] if len(sys.argv) > 2: self.team_need_flash = int(sys.argv[2]) - 1 if len(sys.argv) > 3: self.flash_cond = int(sys.argv[3]) self.old_mission = 'exp' self.ships_need_flash = [] self.min_expdition_time = 0 # self.t=threading.Thread(target=self.main) # self.t.setDaemon(True) # self.t.start() # self.tid=self.t.ident self.handle, self.tid = win32process.beginthreadex( None, 0, self.main, (), 0)
def Demo( prog_id ): # First create the object object = Dispatch(prog_id) print "Thread", GetCurrentThreadId(), "creating object" created_id = object.GetCreatedThreadId() print "Object reports it was created on thread", created_id # Now create the threads, remembering the handles. handles = [] for i in range(3): # As we are not allowed to pass the object directly between # apartments, we need to marshal it. object_stream = CoMarshalInterThreadInterfaceInStream( IID_IDispatch, object ) # Build an argument tuple for the thread. args = (object_stream,) handle, id = beginthreadex(None, 0, WorkerThread, args, 0) handles.append(handle) # Now we have all the threads running, wait for them to terminate. # also remember how many times we are asked to pump messages. num_pumps = 0 while handles: # A quirk in MsgWaitForMultipleObjects means we must wait # for each event one at at time rc = MsgWaitForMultipleObjects(handles, 0, 5000, QS_ALLINPUT) if rc >= WAIT_OBJECT_0 and rc < WAIT_OBJECT_0+len(handles): # A thread finished - remove its handle. del handles[rc-WAIT_OBJECT_0] elif rc==WAIT_OBJECT_0 + len(handles): # Waiting message num_pumps = num_pumps + 1 PumpWaitingMessages() else: print "Nothing seems to be happening", print "but I will keep waiting anyway..." print "Pumped messages", num_pumps, "times" print "Demo of", prog_id, "finished."
def start(self): self.handle, self.tid = win32process.beginthreadex(None, 0, self.run, (), 0)