python - Method to make a new twisted reactor? -


I am creating an IRC log bot which saves thel logs datewise. I want to shut down the current reactor and create a new program (this is because it will save the log in a new file). I wrote a sample program but it is unable to work -

  def event (): if any date_change: do not have to do general work which is to be done other: the current reactor is a new reactor Here is the actual code I am using:  
  def irc_NICK (auto, prefix, parameter): when called "" " An IRC user changes their alias "" "old_nick = prefix.split ('!') [0] new_nick = params [0] if self.factory.filename.find (file_name_gen ()) = - 1: self.logger Log (". & Lt; them & gt; / em>;"% (old_nick, new_nick), 1) left: print "% s now known as% s new itng" reactor.stop () Irc.IRCClient.connectionLost (auto, "change day") #earlier LogBotFactory object f f1 = LogBotFactory ("meeting test", file_name_gen ()) reactor.connectTCP ("irc.freenode.net", 6667, F1) Reactor.run   

The second logbot factory object is created, but due to some uncontrolled error the program stops, I think that is getting trackback ... < / P>

  1971-01-02 23: 59: 41 + 0530 [-] 1971-01-02 23: 59: 41 + 0530 [-] Starting factory & lt; __ Main __. LogBotFactory example at 0x27318c0 & gt; 1971/01/03 00: 00: 10 + 0530 [LogBot, Customer] New itng 1971/01/03 00: 00:. 10 + 0530 [LogBot, Client] Start of the factory & lt; LogBotFactory example on main __ 0x2989cb0 & gt; 1971-01-03 00: 00: 10 + 0530 [Logbot, Client] Unchecked Error Traceback (Most Recent Call End): File "/usr/lib/python2.7/dist-packages/twisted/internet/tcp Py ", line 221, in the _dataReceived rval = self.protocol.dataReceived (data) file" /usr/lib/python2.7/dist-packages/twisted/words/protocols/irc.py ", line 2412, received in data was done. Lean receiver .dataReceived (auto, data.replace ('\ r', '')), file "/usr/lib/python2.7/dist-packages/twisted/protocols/basic.py", in line 581 dataReceived = Self-lineline (line) file "/usr/lib/python2.7/dist-packages/twisted/words/protocols/irc.py", line 2420, self-generated from the line. Handle Commands (command, prefix, params) --- and lieutenant; Exception caught here & gt; --- File "/usr/lib/python2.7/dist-packages/twisted/words/protocols/irc.py", line 2464, the command in the handle (prefix, parameter) file "IRCP.", Line 141, "/usr/lib/python2.7/dist-packages/twisted/internet/base.py" in the IRC_Anique Reactor.Ren () file, line 1191, while running itself. Startings (installsillalahalllers = installsinalhandslers) file "/ usr / lib /python2.7/dist-packages/twisted/internet/base.py", line 1171, initially retirebase. Startering (self) file "/usr/lib/python2.7/dist-packages/twisted/internet/base PE", line 681, is beginning to raise the error. Try again () twisted.internet.error.ReactorAlreadyRunning: 1971-01-03 00: 00: 10 + 0530 [-] The main loop terminated.   

I'm new to Twisted Twist Please help, thank you.

  print "new itng" reactor.stop () irc.IRCClient logging formatting object f f1 = LogBotFactory ("meeting-test", file_name_gen ()) reactor.connect TCP ("irc.freenode.net", 6667, F1) reactor.ron ()   

this problem solved It's easy to do as much as you think. Remove the lines reactor.top () and reactor.ron () and you will all be set. In other words, the reactor is just going on.

Separately, you need to change the line irc.IRCClient.connectionLost (auto, "days change") with self.loseConnection () . Calling connectionLost does not close connection When the connection is closed, it is called becomes if you call it yourself, then your program can think That connection has been discontinued, but it will not be stopped actually - and after that you will be out of resources and your program will win.

You should only stop the reactor while using twisted (usually before leaving your program).

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -