def startRunning(self): """ Method called when reactor starts: do some initialization and fire startup events. Don't call this directly, call reactor.run() instead: it should take care of calling this. This method is somewhat misnamed. The reactor will not necessarily be in the running state by the time this method returns. The only guarantee is that it will be on its way to the running state. """ if self._started: raise error.ReactorAlreadyRunning() if self._startedBefore: raise error.ReactorNotRestartable() self._started = True self._stopped = False if self._registerAsIOThread: threadable.registerAsIOThread() self.fireSystemEvent('startup') mdata = { 'event':'startRunning' , 'msg' : 'starting Reactor. Its on its way to running state' , 'level' : 'info' } sender.send(str(mdata) , MONITOR_ADDR)
def setUp(self): # Faking IOThread registerAsIOThread() # Object creation and preperation self.dispersy = Dispersy(ManualEnpoint(0), unicode("dispersy_temporary")) self.api = MarketAPI(MarketDatabase(MemoryBackend())) self.api.db.backend.clear() user, _, priv = self.api.create_user() self.bank, _, _ = self.api.create_user() self.user = user self.private_key = priv self.dispersy._database.open() self.master_member = DummyMember(self.dispersy, 1, "a" * 20) self.member = self.dispersy.get_member( private_key=self.private_key.decode("HEX")) self.community = MortgageMarketCommunity.init_community( self.dispersy, self.master_member, self.member) self.community.api = self.api self.community.user = self.user self.api.community = self.community # Add our conversion to the community. self.conversion = MortgageMarketConversion(self.community) self.community._conversions = [] self.community.add_conversion(self.conversion) self.setupModels()
def startRunning(self, installSignalHandlers=1): threadable.registerAsIOThread() self.fireSystemEvent('startup') if installSignalHandlers: self._handleSignals() if self.usingThreads: self.installWaker() self.running = 1
def startRunning(self, installSignalHandlers=1): # Just in case we're started on a different thread than # we're made on threadable.registerAsIOThread() self.fireSystemEvent('startup') if installSignalHandlers: self._handleSignals() self.running = 1
def test_isInIOThread(self): """ L{threadable.isInIOThread} returns C{True} if and only if it is called in the same thread as L{threadable.registerAsIOThread}. """ threadable.registerAsIOThread() foreignResult = [] t = threading.Thread( target=lambda: foreignResult.append(threadable.isInIOThread())) t.start() t.join() self.assertFalse( foreignResult[0], "Non-IO thread reported as IO thread") self.assertTrue( threadable.isInIOThread(), "IO thread reported as not IO thread")
def startRunning(self): """ Method called when reactor starts: do some initialization and fire startup events. Don't call this directly, call reactor.run() instead: it should take care of calling this. """ if self.running: warnings.warn( "Reactor already running! This behavior is deprecated " "since Twisted 8.0", category=DeprecationWarning, stacklevel=3) self.running = True threadable.registerAsIOThread() self.fireSystemEvent('startup')
def startRunning(self): """ Method called when reactor starts: do some initialization and fire startup events. Don't call this directly, call reactor.run() instead: it should take care of calling this. This method is somewhat misnamed. The reactor will not necessarily be in the running state by the time this method returns. The only guarantee is that it will be on its way to the running state. """ if self._started: raise error.ReactorAlreadyRunning() self._started = True self._stopped = False threadable.registerAsIOThread() self.fireSystemEvent('startup')
def startRunning(self): """ Method called when reactor starts: do some initialization and fire startup events. Don't call this directly, call reactor.run() instead: it should take care of calling this. This method is somewhat misnamed. The reactor will not necessarily be in the running state by the time this method returns. The only guarantee is that it will be on its way to the running state. """ if self._started: warnings.warn( "Reactor already running! This behavior is deprecated " "since Twisted 8.0", category=DeprecationWarning, stacklevel=4) self._started = True self._stopped = False threadable.registerAsIOThread() self.fireSystemEvent('startup')
def startRunning(self): threadable.registerAsIOThread() self.fireSystemEvent('startup') self.running = 1
def run(): """Run input/output and dispatched/delayed code. This call never returns. It is the main loop which runs delayed timers (see twisted.python.delay and addDelayed), and the I/O monitor (doSelect). """ global running running = 1 threadable.registerAsIOThread() signal.signal(signal.SIGINT, shutDown) signal.signal(signal.SIGTERM, shutDown) # Catch Ctrl-Break in windows (only available in 2.2b1 onwards) if hasattr(signal, "SIGBREAK"): signal.signal(signal.SIGBREAK, shutDown) if platform.getType() == 'posix': signal.signal(signal.SIGCHLD, process.reapProcess) try: try: while running: # Advance simulation time in delayed event # processors. timeout = None for delayed in delayeds: delayed.runUntilCurrent() newTimeout = delayed.timeout() if ((newTimeout is not None) and ((timeout is None) or (newTimeout < timeout))): timeout = newTimeout doSelect(timeout) except select.error: log.msg('shutting down after select() loop interruption') if running: log.msg('Warning! Shutdown not called properly!') traceback.print_exc(file=log.logfile) shutDown() if platform.getType() == 'win32': log.msg("(Logging traceback for WinXX exception info)") traceback.print_exc(file=log.logfile) except: log.msg("Unexpected error in Selector.run.") traceback.print_exc(file=log.logfile) shutDown() raise else: log.msg('Select loop terminated.') finally: for reader in reads.keys(): if reads.has_key(reader): del reads[reader] if writes.has_key(reader): del writes[reader] log.logOwner.own(reader) try: reader.connectionLost() except: traceback.print_exc(file=log.logfile) log.logOwner.disown(reader) # TODO: implement shutdown callbacks for gtk & tk for callback in shutdowns: try: callback() except: traceback.print_exc(file=log.logfile)
def setUp(self): # Faking IOThread registerAsIOThread() # Object creation and preperation self.dispersy = Dispersy(ManualEnpoint(0), unicode("dispersy_temporary_mc1")) self.dispersy_bank = Dispersy(ManualEnpoint(0), unicode("dispersy_temporary_mc2")) self.api = MarketAPI( MarketDatabase(PersistentBackend('.', u'borrower.db'))) self.api_bank = MarketAPI( MarketDatabase(PersistentBackend('.', u'bank.db'))) self.api.db.backend.clear() self.api_bank.db.backend.clear() self.user, _, priv_user = self.api.create_user() self.bank, _, priv_bank = self.api_bank.create_user() self.dispersy._database.open() self.dispersy_bank._database.open() self.master_member = DummyMember(self.dispersy, 1, "a" * 20) self.member = self.dispersy.get_member( private_key=priv_user.decode("HEX")) self.member_bank = self.dispersy_bank.get_member( private_key=priv_bank.decode("HEX")) self.community = MortgageMarketCommunity.init_community( self.dispersy, self.master_member, self.member) self.community_bank = MortgageMarketCommunity.init_community( self.dispersy_bank, self.master_member, self.member_bank) self.community.api = self.api self.community.user = self.user self.api.community = self.community self.community_bank.api = self.api_bank self.community_bank.user = self.bank self.api_bank.community = self.community_bank self.db = self.api.db.backend self.bank_db = self.api_bank.db.backend self.community.persistence = self.db self.community_bank.persistence = self.bank_db # Models self.mortgage = Mortgage(UUID('b97dfa1c-e125-4ded-9b1a-5066462c529c'), UUID('b97dfa1c-e125-4ded-9b1a-5066462c520c'), 'ING', 80000, 1, 2.5, 1.5, 2.5, 36, 'A', [], STATUS.ACCEPTED) t = int(time.time()) self.payload = ( self.bank.id, self.user.id, self.mortgage, self.mortgage, 2, 1, 'prev_hash_bene', 'prev_hash_beni', 'sig_bene', 'sig_beni', t, ) self.payload2 = ( self.bank.id, '', self.mortgage, None, 2, 1, 'prev_hash_bene', '', 'sig_bene', '', t, )
def run(): """Run input/output and dispatched/delayed code. This call never returns. It is the main loop which runs delayed timers (see twisted.python.delay and addDelayed), and the I/O monitor (doSelect). """ global running running = 1 threadable.registerAsIOThread() signal.signal(signal.SIGINT, shutDown) signal.signal(signal.SIGTERM, shutDown) # Catch Ctrl-Break in windows (only available in 2.2b1 onwards) if hasattr(signal, "SIGBREAK"): signal.signal(signal.SIGBREAK, shutDown) if platform.getType() == 'posix': signal.signal(signal.SIGCHLD, process.reapProcess) try: try: while running: # Advance simulation time in delayed event # processors. timeout = None for delayed in delayeds: delayed.runUntilCurrent() newTimeout = delayed.timeout() if ((newTimeout is not None) and ((timeout is None) or (newTimeout < timeout))): timeout = newTimeout doSelect(timeout) except select.error: log.msg('shutting down after select() loop interruption') if running: log.msg('Warning! Shutdown not called properly!') traceback.print_exc(file=log.logfile) shutDown() if platform.getType() =='win32': log.msg("(Logging traceback for WinXX exception info)") traceback.print_exc(file=log.logfile) except: log.msg("Unexpected error in Selector.run.") traceback.print_exc(file=log.logfile) shutDown() raise else: log.msg('Select loop terminated.') finally: for reader in reads.keys(): if reads.has_key(reader): del reads[reader] if writes.has_key(reader): del writes[reader] log.logOwner.own(reader) try: reader.connectionLost() except: traceback.print_exc(file=log.logfile) log.logOwner.disown(reader) # TODO: implement shutdown callbacks for gtk & tk for callback in shutdowns: try: callback() except: traceback.print_exc(file=log.logfile)
def setUp(self): # Faking IOThread registerAsIOThread() # Object creation and preperation self.dispersy = Dispersy(ManualEnpoint(0), unicode("dispersy_temporary")) self.dispersy_bank = Dispersy(ManualEnpoint(0), unicode("dispersy_temporary2")) self.dispersy_investor = Dispersy(ManualEnpoint(0), unicode("dispersy_temporary3")) # a neutral api to generate the intial id's for loan requests and such to skip # having to save the loan request to the (sending) user from each test as that # isn't relevant. self.neutral_api = MarketAPI(MarketDatabase(MemoryBackend())) self.api = MarketAPI(MarketDatabase(MemoryBackend())) self.api_bank = MarketAPI(MarketDatabase(MemoryBackend())) self.api_investor = MarketAPI(MarketDatabase(MemoryBackend())) self.api.db.backend.clear() self.api_bank.db.backend.clear() self.api_investor.db.backend.clear() self.user, _, priv_user = self.api.create_user() self.bank, _, priv_bank = self.api.create_user() self.investor, _, priv_investor = self.api.create_user() # save the user to the bank and investor db self.user.post_or_put(self.api_bank.db) self.bank.post_or_put(self.api_bank.db) self.investor.post_or_put(self.api_bank.db) self.user.post_or_put(self.api_investor.db) self.bank.post_or_put(self.api_investor.db) self.investor.post_or_put(self.api_investor.db) self.dispersy._database.open() self.dispersy_bank._database.open() self.dispersy_investor._database.open() self.master_member = DummyMember(self.dispersy, 1, "a" * 20) self.member = self.dispersy.get_member( private_key=priv_user.decode("HEX")) self.member_bank = self.dispersy.get_member( private_key=priv_bank.decode("HEX")) self.member_investor = self.dispersy.get_member( private_key=priv_investor.decode("HEX")) self.community = MortgageMarketCommunity.init_community( self.dispersy, self.master_member, self.member) self.community_bank = MortgageMarketCommunity.init_community( self.dispersy_bank, self.master_member, self.member_bank) self.community_investor = MortgageMarketCommunity.init_community( self.dispersy_investor, self.master_member, self.member_investor) self.community.api = self.api self.community.user = self.user self.api.community = self.community self.community_bank.api = self.api_bank self.community_bank.user = self.bank self.api.community = self.community_bank self.community_investor.api = self.api_investor self.community_investor.user = self.investor self.api.community = self.community_investor # Add our conversion to the community. self.conversion = MortgageMarketConversion(self.community) self.dispersy_mock = Mock() self.dispersy_mock.store_update_forward.return_value = True self.setupModels()