twisted.internet.error.ReactorNotRestartable

#1

Hi,

In my server (using autobahn, twisted) I need to listen on one port and clients will be connected to that port, then 15 mins later need to connect the server with other server. In other words:

  • Listen 8800
  • js clients connects and connected on port 8800
  • Wait for 15 mins
  • Connect to another server on 9900 for clustering.

I am trying to do this, following way:

  • Listen 8000 (reactor.run())
  • wait for 15 mins (.callLater())
  • Connect to another server (again reactor.run())

reactor.listenTCP(port, ws)

reactor.run()

wait 15 mins

reactor.connectTCP(ip, port, factory)

reactor.run()

On this I am getting twisted.internet.error.ReactorNotRestartable error. Can any one tell me how to do this (if possible without disconnecting js clients).

0 Likes

#2

Chuck,

you don't need to "start a 2nd reactor" to do that:

def foo():
   reactor.connectTCP(...)

reactor.callLater(15*60, foo)
reactor.listenTCP(..)
reactor.run()

Cheers,
/Tobias

···

Am 13.03.2014 13:21, schrieb Chuck James:

Hi,

       In my server (using autobahn, twisted) I need to listen on one
port and clients will be connected to that port, then 15 mins later need
to connect the server with other server. In other words:

  * Listen 8800
  * js clients connects and connected on port 8800
  * Wait for 15 mins
  * Connect to another server on 9900 for clustering.

0 Likes

#3

But my requirement is to listen port first and 15 mins later connect to another server. Not one after one but after 15 mins of delay.

Thanks,
Amitabh Arya

···

On Mar 13, 2014, at 9:42 AM, Tobias Oberstein <tobias.o...@gmail.com> wrote:

Am 13.03.2014 13:21, schrieb Chuck James:

Hi,

      In my server (using autobahn, twisted) I need to listen on one
port and clients will be connected to that port, then 15 mins later need
to connect the server with other server. In other words:

* Listen 8800
* js clients connects and connected on port 8800
* Wait for 15 mins
* Connect to another server on 9900 for clustering.

Chuck,

you don't need to "start a 2nd reactor" to do that:

def foo():
reactor.connectTCP(...)

reactor.callLater(15*60, foo)
reactor.listenTCP(..)
reactor.run()

Cheers,
/Tobias

--
You received this message because you are subscribed to a topic in the Google Groups "Autobahn" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/autobahnws/rXMFD6mgzs0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to autobahnws+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

0 Likes

#4

But my requirement is to listen port first and 15 mins later connect to another server. Not one after one but after 15 mins of delay.

sure, and that is what the code below does.

btw: are you "Chuck" or "Amitabh" or whom I am talking to?

···

Am 13.03.2014 14:56, schrieb Amitabh@tech:

Thanks,
Amitabh Arya

On Mar 13, 2014, at 9:42 AM, Tobias Oberstein <tobias.o...@gmail.com> wrote:

Am 13.03.2014 13:21, schrieb Chuck James:

Hi,

       In my server (using autobahn, twisted) I need to listen on one
port and clients will be connected to that port, then 15 mins later need
to connect the server with other server. In other words:

  * Listen 8800
  * js clients connects and connected on port 8800
  * Wait for 15 mins
  * Connect to another server on 9900 for clustering.

Chuck,

you don't need to "start a 2nd reactor" to do that:

def foo():
  reactor.connectTCP(...)

reactor.callLater(15*60, foo)
reactor.listenTCP(..)
reactor.run()

Cheers,
/Tobias

--
You received this message because you are subscribed to a topic in the Google Groups "Autobahn" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/autobahnws/rXMFD6mgzs0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to autobahnws+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

0 Likes

#5

:slight_smile: My name is Amitabh I work at Miami USA, and my company give me another name Chuck James as Amitabh is hard to speak for some of them. So most of my friend call me Chuck. But when I write/reply emails I use Amitabh as thats what I have on my resume. I know confusing sorry :).

I do understand your code, but here is my requirement in detail:

I have an application.xml which have information about application multiple ports and other servers. My server application (autobahn) supposed to run that xml after every 15 mins. And connect/disconnect to other server accordingly. In this 15 mins the server admin guy can modify the xml incase of code push or reset the cluster.

But I used your code and got my issue fixed :slight_smile: thanks a ton buddy.

So, in short, in reactor is running, we just need to use connectTCP or ListenTCP and it will auto connect or auto start listening. Thats great about twisted :).

I have small question, Can we listen/connect ports on a subprocess also (Subprocess using reactor.spawnProcess method). If yes then, is there a default timeout for subprocesses at linux?

I am just using task.LoopingCall(self.checkForCluster) instead of callLater function. But it’s working I guess.

Thanks,

Amitabh Arya

···

On Mar 13, 2014, at 9:58 AM, Tobias Oberstein tobias.o...@gmail.com wrote:

Am 13.03.2014 14:56, schrieb Amitabh@tech:

But my requirement is to listen port first and 15 mins later connect to another server. Not one after one but after 15 mins of delay.

sure, and that is what the code below does.

btw: are you “Chuck” or “Amitabh” or whom I am talking to?

Thanks,
Amitabh Arya

On Mar 13, 2014, at 9:42 AM, Tobias Oberstein tobias.o...@gmail.com wrote:

Am 13.03.2014 13:21, schrieb Chuck James:

Hi,

   In my server (using autobahn, twisted) I need to listen on one

port and clients will be connected to that port, then 15 mins later need
to connect the server with other server. In other words:

  • Listen 8800
  • js clients connects and connected on port 8800
  • Wait for 15 mins
  • Connect to another server on 9900 for clustering.

Chuck,

you don’t need to “start a 2nd reactor” to do that:

def foo():
reactor.connectTCP(…)

reactor.callLater(15*60, foo)
reactor.listenTCP(…)
reactor.run()

Cheers,
/Tobias


You received this message because you are subscribed to a topic in the Google Groups “Autobahn” group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/autobahnws/rXMFD6mgzs0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to autobahnws+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


You received this message because you are subscribed to a topic in the Google Groups “Autobahn” group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/autobahnws/rXMFD6mgzs0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to autobahnws+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

0 Likes

#6

:slight_smile: My name is Amitabh I work at Miami USA, and my company give me
another name Chuck James as Amitabh is hard to speak for some of them.
So most of my friend call me Chuck. But when I write/reply emails I use
Amitabh as thats what I have on my resume. I know confusing sorry :).

Ahhh;) Thanks!

"Amitabh": also complicated for Germans .. in fact, I have no clue how to pronounce correctly.

I do understand your code, but here is my requirement in detail:
I have an application.xml which have information about application
multiple ports and other servers. My server application (autobahn)
supposed to run that xml after every 15 mins. And connect/disconnect to
other server accordingly. In this 15 mins the server admin guy can
modify the xml incase of code push or reset the cluster.

I see. But no problem also:

def foo():
    config = read_config()
    reactor.connectTCP(config.port, config.host, ...)

But I used your code and got my issue fixed :slight_smile: thanks a ton buddy.

Great.

So, in short, in reactor is running, we just need to use connectTCP or
ListenTCP and it will auto connect or auto start listening. Thats great
about twisted :).

It's working like this:

1) When your program starts, you wire up everything that should happen .. now or in the future.

2) Start the reactor.

Then Twisted will figure out and make sure everything happens according to how you wired up stuff.

"auto-reconnect": If you mean, automatically reconnect to a host (previously connected to) when connection is lost, then no, you need to do that yourself. Or you Twisted ReconnectingClientFactory ..

*I have small question, Can we listen/connect ports on a subprocess also
(Subprocess using reactor.spawnProcess method). If yes then, is there a
default timeout for subprocesses at linux?*

You can spawn a subprocess from Twisted. That subprocess can be anything .. it can be Python based or not. And if Python, it can use Twisted or not. If so, it'll run it's own reactor.

https://twistedmatrix.com/documents/current/core/howto/process.html

I am just using task.LoopingCall(self.__checkForCluster__) instead of
callLater function. But it’s working I guess.

task.LoopingCall is a little bit sugar that simplifies stuff when you want to do something every N secs.

But its easy to do manually also:

def foo():
    # do stuff
    reactor.callLater(1000, foo)

foo()

reactor.run()

Cheers,
/Tobias

···

Am 13.03.2014 15:55, schrieb Amitabh Arya:

Thanks,
Amitabh Arya

On Mar 13, 2014, at 9:58 AM, Tobias Oberstein > <tobias.o...@gmail.com <mailto:tobias.o...@gmail.com>> wrote:

Am 13.03.2014 14:56, schrieb Amitabh@tech:

But my requirement is to listen port first and 15 mins later connect
to another server. Not one after one but after 15 mins of delay.

sure, and that is what the code below does.

btw: are you "Chuck" or "Amitabh" or whom I am talking to?

Thanks,
Amitabh Arya

On Mar 13, 2014, at 9:42 AM, Tobias Oberstein >>>> <tobias.o...@gmail.com <mailto:tobias.o...@gmail.com>> wrote:

Am 13.03.2014 13:21, schrieb Chuck James:

Hi,

      In my server (using autobahn, twisted) I need to listen on one
port and clients will be connected to that port, then 15 mins later
need
to connect the server with other server. In other words:

* Listen 8800
* js clients connects and connected on port 8800
* Wait for 15 mins
* Connect to another server on 9900 for clustering.

Chuck,

you don't need to "start a 2nd reactor" to do that:

def foo():
reactor.connectTCP(...)

reactor.callLater(15*60, foo)
reactor.listenTCP(..)
reactor.run()

Cheers,
/Tobias

--
You received this message because you are subscribed to a topic in
the Google Groups "Autobahn" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/autobahnws/rXMFD6mgzs0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
autobahnws+...@googlegroups.com
<mailto:autobahnws+...@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the
Google Groups "Autobahn" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/autobahnws/rXMFD6mgzs0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
autobahnws+...@googlegroups.com
<mailto:autobahnws+...@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google
Groups "Autobahn" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to autobahnws+...@googlegroups.com
<mailto:autobahnws+...@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.

0 Likes

#7

Thanks for the reply, I got it and will run separate reactor.run(), when I will use the reactor.spawnProcess.

“Amitabh": also complicated for Germans … in fact, I have no clue how to pronounce correctly.

Well, then I will not mind if you will call me Chuck, Hopefully that would be easy for you :).

Have a great day and pleasant evening.

···

On Mar 13, 2014, at 11:05 AM, Tobias Oberstein tobias.o...@gmail.com wrote:

Am 13.03.2014 15:55, schrieb Amitabh Arya:

:slight_smile: My name is Amitabh I work at Miami USA, and my company give me
another name Chuck James as Amitabh is hard to speak for some of them.
So most of my friend call me Chuck. But when I write/reply emails I use
Amitabh as thats what I have on my resume. I know confusing sorry :).

Ahhh;) Thanks!

“Amitabh”: also complicated for Germans … in fact, I have no clue how to pronounce correctly.

I do understand your code, but here is my requirement in detail:
I have an application.xml which have information about application
multiple ports and other servers. My server application (autobahn)
supposed to run that xml after every 15 mins. And connect/disconnect to
other server accordingly. In this 15 mins the server admin guy can
modify the xml incase of code push or reset the cluster.

I see. But no problem also:

def foo():
config = read_config()
reactor.connectTCP(config.port, config.host, …)

But I used your code and got my issue fixed :slight_smile: thanks a ton buddy.

Great.

So, in short, in reactor is running, we just need to use connectTCP or
ListenTCP and it will auto connect or auto start listening. Thats great
about twisted :).

It’s working like this:

  1. When your program starts, you wire up everything that should happen … now or in the future.

  2. Start the reactor.

Then Twisted will figure out and make sure everything happens according to how you wired up stuff.

“auto-reconnect”: If you mean, automatically reconnect to a host (previously connected to) when connection is lost, then no, you need to do that yourself. Or you Twisted ReconnectingClientFactory …

I have small question, Can we listen/connect ports on a subprocess also
(Subprocess using reactor.spawnProcess method). If yes then, is there a
default timeout for subprocesses at linux?

You can spawn a subprocess from Twisted. That subprocess can be anything … it can be Python based or not. And if Python, it can use Twisted or not. If so, it’ll run it’s own reactor.

https://twistedmatrix.com/documents/current/core/howto/process.html

I am just using task.LoopingCall(self.checkForCluster) instead of
callLater function. But it’s working I guess.

task.LoopingCall is a little bit sugar that simplifies stuff when you want to do something every N secs.

But its easy to do manually also:

def foo():

do stuff

reactor.callLater(1000, foo)

foo()

reactor.run()

Cheers,
/Tobias

Thanks,
Amitabh Arya

On Mar 13, 2014, at 9:58 AM, Tobias Oberstein > > <tobias.o...@gmail.com mailto:tobias.o...@gmail.com> wrote:

Am 13.03.2014 14:56, schrieb Amitabh@tech:

But my requirement is to listen port first and 15 mins later connect
to another server. Not one after one but after 15 mins of delay.

sure, and that is what the code below does.

btw: are you “Chuck” or “Amitabh” or whom I am talking to?

Thanks,
Amitabh Arya

On Mar 13, 2014, at 9:42 AM, Tobias Oberstein > > > > > <tobias.o...@gmail.com mailto:tobias.o...@gmail.com> wrote:

Am 13.03.2014 13:21, schrieb Chuck James:

Hi,

 In my server (using autobahn, twisted) I need to listen on one

port and clients will be connected to that port, then 15 mins later
need
to connect the server with other server. In other words:

  • Listen 8800
  • js clients connects and connected on port 8800
  • Wait for 15 mins
  • Connect to another server on 9900 for clustering.

Chuck,

you don’t need to “start a 2nd reactor” to do that:

def foo():
reactor.connectTCP(…)

reactor.callLater(15*60, foo)
reactor.listenTCP(…)
reactor.run()

0 Likes