def run_efsharp_thread(self, runner): from System.Threading import Thread, ThreadStart, ApartmentState thread = Thread(ThreadStart(runner)) thread.SetApartmentState(ApartmentState.STA) thread.Start() return thread
# 5. make sure the dom is valid if not error_occurred: if int(dom.status_code) == 1: retval = dom # success else: if lasttry: raise DatabaseConnectionError("Comic Vine", url, 'code {0}: "{1}"'.format(dom.status_code, dom.error), dom.status_code ) else: error_occurred = True # 6. return the valid dom, or if error occurred, retry once if error_occurred: log.debug('ERROR OCCURRED CONTACTING COMICVINE. RETRYING...') t = Thread(ThreadStart(lambda x=0: Thread.CurrentThread.Sleep(2500))) t.Start() t.Join() return __get_dom(url, True) else: return retval # ============================================================================= def __get_page(url): ''' Reads the webpage at the given URL into a new string, which is returned. The returned value may be None if a problem is encountered, OR an exception may be thrown. If the exception is a DatabaseConnectionError, that represents an problem connecting to the Comic Vine database. ''' wait_until_ready() # throttle request speed to make ComicVine happy
print "Unable to set received data to received variable" try: sock.close() except: print "Unable to close the connection" try: print "Sent: {}".format(data) print "Received: {}".format(received) except: print "Unable to print a simple line" try: spk.Speak(received) except: print "Unable to speak received data" except: print "Unable to communicate with the brain." sre.RecognizeAsync(RecognizeMode.Multiple) sre.SpeechRecognized += OnSpeechRecognized sre.RecognizeAsync(RecognizeMode.Multiple) raw_input('Press ENTER to quit\n\n') if __name__ == '__main__': if sys.platform == 'cli': from System.Threading import Thread, ThreadStart thread = Thread(ThreadStart(main)) thread.Start() else: main()
def btnStartPressed(self, sender, args): Misc.SetSharedValue('run','True') Misc.SendMessage('Starting',80) def attack(): while Misc.ReadSharedValue('run') == 'True': eNumber = 0 fil = Mobiles.Filter() fil.Enabled = True fil.RangeMax = 1 fil.Notorieties = List[Byte](bytes([3,4,5,6])) if Misc.ReadSharedValue('dAxe') == 'True': enemies = Mobiles.ApplyFilter(fil) Mobiles.Select(enemies,'Nearest') for enemy in enemies: eNumber += 1 if eNumber == 1: eNumber = 0 if not Player.HasSpecial: Player.WeaponPrimarySA() Player.Attack(enemy) if eNumber == 2: eNumber = 0 if not Player.SpellIsEnabled('Momentum Strike'): Spells.CastBushido('Momentum Strike') Player.Attack(enemy) if eNumber > 2 : eNumber = 0 if not Player.HasSpecial: Player.WeaponSecondarySA() Player.Attack(enemy) Misc.Pause(250) if Misc.ReadSharedValue('bStaff') == 'True': enemies = Mobiles.ApplyFilter(fil) Mobiles.Select(enemies,'Nearest') for enemy in enemies: eNumber += 1 if eNumber == 1: eNumber = 0 if not Player.HasSpecial: Player.WeaponPrimarySA() Player.Attack(enemy) if eNumber >= 2: eNumber = 0 if not Player.SpellIsEnabled('Momentum Strike'): Spells.CastBushido('Momentum Strike') Player.Attack(enemy) Misc.Pause(500) def cast(): while Misc.ReadSharedValue('run') == 'True': if Misc.ReadSharedValue('bush') == 'True': bush() if Misc.ReadSharedValue('eoo') == 'True': enemyOfOne() if Misc.ReadSharedValue('consec') == 'True': consecrateWep() if Misc.ReadSharedValue('honor') == 'True': honorNearest() if Misc.ReadSharedValue('devFury') == 'True': divineFury() if Misc.ReadSharedValue('onslaught') == 'True': onslaughtMastery() if Misc.ReadSharedValue('cAttack') == 'True': counterAttack() if Misc.ReadSharedValue('ojPetal') == 'True': orangePetal() Misc.Pause(500) c = Thread(ThreadStart(cast)) c.Start() t = Thread(ThreadStart(attack)) t.Start() Misc.SetSharedValue('bush','False') Misc.SetSharedValue('eoo','False') Misc.SetSharedValue('consec','False') Misc.SetSharedValue('honor','False') Misc.SetSharedValue('devFury','False') Misc.SetSharedValue('onslaught','False') Misc.SetSharedValue('cAttack','False') Misc.SetSharedValue('ojPetal','False') Misc.SetSharedValue('dAxe','False') Misc.SetSharedValue('bStaff','False') if self.cbC.Checked: Misc.Pause(300) if BandageHeal.Status() == False: BandageHeal.Start() if self.cbA.Checked: Misc.Pause(300) Misc.SetSharedValue('bush','True') if self.cbB.Checked: Misc.Pause(300) Misc.SetSharedValue('eoo','True') if self.cbD.Checked: Misc.Pause(300) Misc.SetSharedValue('consec','True') if self.cbE.Checked: Misc.Pause(300) Misc.SetSharedValue('honor','True') if self.cbF.Checked: Misc.Pause(300) Misc.SetSharedValue('devFury','True') if self.cbG.Checked: Misc.Pause(300) Misc.SetSharedValue('onslaught','True') if self.cbH.Checked: Misc.Pause(300) Misc.SetSharedValue('cAttack','True') if self.cbI.Checked: Misc.Pause(300) Misc.SetSharedValue('ojPetal','True') if self.rbD.Checked: Misc.Pause(300) Misc.SetSharedValue('dAxe','True') if self.rbE.Checked: Misc.Pause(300) Misc.SetSharedValue('bStaff','True')
def btnStartPressed(self, sender, args): Misc.SetSharedValue('run','True') Misc.SetSharedValue('bush','False') Misc.SetSharedValue('eoo','False') Misc.SetSharedValue('consec','False') Misc.SetSharedValue('honor','False') Misc.SetSharedValue('devFury','False') Misc.SetSharedValue('onslaught','False') Misc.SetSharedValue('cAttack','False') Misc.SetSharedValue('ojPetal','False') Misc.SetSharedValue('apple','False') Misc.SetSharedValue('chase','False') Misc.SetSharedValue('insure','False') Misc.SetSharedValue('dAxe','False') Misc.SetSharedValue('bStaff','False') Misc.SetSharedValue('rail','False') Misc.SetSharedValue('bonecutter','False') Misc.SendMessage('Starting',80) def attack(): while Misc.ReadSharedValue('run') == 'True': eNumber = 0 fil = Mobiles.Filter() fil.Enabled = True fil.RangeMax = 1 fil.Notorieties = List[Byte](bytes([3,4,5,6])) if Misc.ReadSharedValue('dAxe') == 'True': enemies = Mobiles.ApplyFilter(fil) Mobiles.Select(enemies,'Nearest') for enemy in enemies: eNumber += 1 if eNumber == 1: eNumber = 0 if not Player.HasSpecial: Player.WeaponPrimarySA() Player.Attack(enemy) if eNumber == 2: eNumber = 0 if not Player.SpellIsEnabled('Momentum Strike'): Spells.CastBushido('Momentum Strike') Player.Attack(enemy) if eNumber > 2 : eNumber = 0 if not Player.HasSpecial: Player.WeaponSecondarySA() Player.Attack(enemy) Misc.Pause(250) if Misc.ReadSharedValue('bStaff') == 'True': enemies = Mobiles.ApplyFilter(fil) Mobiles.Select(enemies,'Nearest') for enemy in enemies: eNumber += 1 if eNumber == 1: eNumber = 0 if not Player.HasSpecial: Player.WeaponPrimarySA() Player.Attack(enemy) if eNumber >= 2: eNumber = 0 if not Player.SpellIsEnabled('Momentum Strike'): Spells.CastBushido('Momentum Strike') Player.Attack(enemy) Misc.Pause(500) def cast(): while Misc.ReadSharedValue('run') == 'True': if Misc.ReadSharedValue('bush') == 'True': bush() if Misc.ReadSharedValue('eoo') == 'True': enemyOfOne() if Misc.ReadSharedValue('consec') == 'True': consecrateWep() if Misc.ReadSharedValue('honor') == 'True': honorNearest() if Misc.ReadSharedValue('devFury') == 'True': divineFury() if Misc.ReadSharedValue('onslaught') == 'True': onslaughtMastery() if Misc.ReadSharedValue('cAttack') == 'True': counterAttack() if Misc.ReadSharedValue('ojPetal') == 'True': orangePetal() if Misc.ReadSharedValue('insure') == 'True': list = [] for item in Player.Backpack.Contains: list.append(item.Serial) Misc.Pause(50) insure() Misc.Pause(500) def rail(): self.ReadRail() while Misc.ReadSharedValue('chase') == 'True' and Misc.ReadSharedValue('rail') == 'False': chase() Misc.Pause(500) if Misc.ReadSharedValue('run') == 'False': break while Misc.ReadSharedValue('rail') == 'True': for coords in railcoords: go(coords[0],coords[1]) if Misc.ReadSharedValue('run') == 'False': break if Misc.ReadSharedValue('chase') == 'True': chase() Misc.Pause(500) def actions(): while Misc.ReadSharedValue('run') == 'True': if Misc.ReadSharedValue('apple') == 'True': apple() if Misc.ReadSharedValue('bonecutter') == 'True': bonecutter(wep) Misc.Pause(1000) if self.cbC.Checked: Misc.Pause(300) if BandageHeal.Status() == False: BandageHeal.Start() if self.cbA.Checked: Misc.Pause(300) Misc.SetSharedValue('bush','True') if self.cbB.Checked: Misc.Pause(300) Misc.SetSharedValue('eoo','True') if self.cbD.Checked: Misc.Pause(300) Misc.SetSharedValue('consec','True') if self.cbE.Checked: Misc.Pause(300) Misc.SetSharedValue('honor','True') if self.cbF.Checked: Misc.Pause(300) Misc.SetSharedValue('devFury','True') if self.cbG.Checked: Misc.Pause(300) Misc.SetSharedValue('onslaught','True') if self.cbH.Checked: Misc.Pause(300) Misc.SetSharedValue('cAttack','True') if self.cbI.Checked: Misc.Pause(300) Misc.SetSharedValue('ojPetal','True') if self.cbJ.Checked: Misc.Pause(300) Misc.SetSharedValue('insure','True') if self.cbK.Checked: Misc.Pause(300) Misc.SetSharedValue('apple','True') if self.cbL.Checked: Misc.Pause(300) Misc.SetSharedValue('chase','True') if self.cbM.Checked: Misc.Pause(300) Misc.SetSharedValue('rail','True') if self.cbN.Checked: Misc.Pause(300) Misc.SetSharedValue('bonecutter','True') Misc.SendMessage('Select Bone Cutter Wep',30) wep = Target.PromptTarget('') while Target.HasTarget(): Misc.Pause(1000) if self.rbD.Checked: Misc.Pause(300) Misc.SetSharedValue('dAxe','True') if self.rbE.Checked: Misc.Pause(300) Misc.SetSharedValue('bStaff','True') c = Thread(ThreadStart(cast)) c.Start() a = Thread(ThreadStart(attack)) a.Start() r = Thread(ThreadStart(rail)) r.Start() act = Thread(ThreadStart(actions)) act.Start()
class Server(SimpleServer): def __init__(self, host, port): SimpleServer.__init__(self, host, port) self.app = None # inject self.model = None # inject self.thread_id = None self.observers = multicast() self.json_from_dict = None # inject @property def url_server(self): return "http://%s:%s" % (self.host, self.port) def StopServer(self): print "stopping server thread..." if self.thread_id: self.thread_id.Abort() self.thread_id = None def StartServer(self): print "starting server thread..." self.thread_id = Thread(ThreadStart(self.serveforever)) self.thread_id.Start() def handle(self, path, method, request, response): #print path, method, request, response cmd = path[0] #print path, len(path) def report_error(inst): msg = "Server exception: %s" % inst print msg return msg if cmd == '': return "G'day" elif cmd == 'modelsize': return 'The model length is %d' % self.model.size elif cmd == 'dumpthings': s = "" for thing in self.model.things: s += str(thing) + '<BR>' return s elif cmd == 'addthing': self.observers.CMD_ADD_THING("fred") return 'The model length is now %d' % self.model.size # REST API elif cmd == 'jsontest': import time return {'status': 'online', 'servertime': time.time()} elif cmd == 'things' and len(path) == 1: try: response.ContentType = "application/json" return self.json_from_dict( self.app.controller.CmdGetThingsAsDict()) except Exception, inst: return report_error(inst) elif cmd == 'things' and len(path) == 2: try: id = path[1] response.ContentType = "application/json" return self.json_from_dict( self.app.controller.CmdGetThingAsDict(id)) except Exception, inst: return report_error(inst)
class Server(SimpleServer): def __init__(self, host, port): SimpleServer.__init__(self, host, port) self.app = None # inject self.model = None # inject self.thread_id = None self.observers = multicast() self.json_from_dict = None # inject @property def url_server(self): return "http://%s:%s" % (self.host, self.port) def StopServer(self): print("stopping server thread...") if self.thread_id: self.thread_id.Abort() self.thread_id = None def StartServer(self): print("starting server thread...") self.thread_id = Thread(ThreadStart(self.serveforever)) self.thread_id.Start() def handle(self, path, method, request, response): # print path, method, request, response cmd = path[0] # print path, len(path) def report_error(inst): msg = "Server exception: %s" % inst print(msg) return msg if cmd == "": return "G'day" elif cmd == "modelsize": return "The model length is %d" % self.model.size elif cmd == "dumpthings": s = "" for thing in self.model.things: s += str(thing) + "<BR>" return s elif cmd == "addthing": self.observers.CMD_ADD_THING("fred") return "The model length is now %d" % self.model.size # REST API elif cmd == "jsontest": import time return {"status": "online", "servertime": time.time()} elif cmd == "things" and len(path) == 1: try: response.ContentType = "application/json" return self.json_from_dict(self.app.controller.CmdGetThingsAsDict()) except Exception as inst: return report_error(inst) elif cmd == "things" and len(path) == 2: try: id = path[1] response.ContentType = "application/json" return self.json_from_dict(self.app.controller.CmdGetThingAsDict(id)) except Exception as inst: return report_error(inst) else: # do the default return SimpleServer.handle(self, path, method, request, response)
def main(): thread = Thread(ThreadStart(app_thread)) thread.SetApartmentState(ApartmentState.STA) thread.Start() thread.Join()
def start(function): wrapper = FunctionWrapper(function, locals()) ts = wrapper.CreateThreadStart() thread = Thread(ts) thread.Start() return thread