Am 17.06.2015 um 16:57 schrieb Raffaele Bianco:
> Hi Tobias,
>
> Thanks for the example, that works for me too. The issue arises when the
> run method takes more than 15 seconds to execute (you can simulate that
> by adding a "time.time".sleep(15) in it)
Using time.sleep() will block the reactor. Don't do that.
You need to sleep without blocking.
E.g. for Twisted:
https://github.com/tavendo/AutobahnPython/blob/master/autobahn/twisted/util.py#L44
and to use
yield autobahn.twisted.util.sleep(15)
>
> I anyway found the culprit. The issue is causes by the options I have in :
>
> "ws":{
> "type":"websocket",
> "options":{
> "auto_ping_interval":10000,
> "auto_ping_timeout":5000,
> "auto_ping_size":4
> }
>
No, this is perfectly fine.
>
>
> I presume that being my component busy churning DB records for more than
> 15 secs (10+5) obviously cannot reply to the ping and crossbar kicks it out.
No, the reason is that you are blocking the reactor. Also note, that
WebSocket ping/pong is completely handled by Crossbar.io already - not
your component (it runs in the router worker).
You must not block the reactor: whether by doing time.sleep() or by
doing blocking DB access.
E.g. for PostgreSQL, we have a doc page here
http://crossbar.io/docs/Database-Programming-with-PostgreSQL/
>
> I'll change the intervals or remove the auto_ping completely.
No, this isn't the solution ..
>
> Thanks for your prompt help,
> Raffaele
>
> On Monday, June 15, 2015 at 7:01:52 PM UTC+2, Tobias Oberstein wrote:
>
> Hi Raffaele,
>
> this works for me:
>
>
https://gist.github.com/oberstet/70901f556271eeceec0e
> <
https://gist.github.com/oberstet/70901f556271eeceec0e>
>
> ```python
> from datetime import datetime
> from twisted.internet.defer import inlineCallbacks
>
> from autobahn.wamp.types import PublishOptions
> from autobahn.twisted.wamp import ApplicationSession
> from autobahn.twisted.wamp import ApplicationRunner
> from autobahn.twisted.util import sleep
>
>
> class MyComponent(ApplicationSession):
>
> @inlineCallbacks
> def onJoin(self, details):
> print("session ready")
> yield self.subscribe(self.run, u"
a.topic.name
> <
http://a.topic.name>")
>
> while True:
> yield self.publish(u"
a.topic.name <
http://a.topic.name>",
> options=PublishOptions(exclude_me=False))
> yield sleep(5)
>
> def run(self):
> print("run at {}".format(datetime.now()))
>
> runner = ApplicationRunner(url=u"ws://localhost:8080/ws",
> realm=u"realm1")
> runner.run(MyComponent)
> ```
>
> and prints this
>
>
> ```console
> (python279_1)oberstet@thinkpad-t430s:~/scm/crossbar$ python test.py
> session ready
> run at 2015-06-15 18:59:39.518969
> run at 2015-06-15 18:59:44.519833
> run at 2015-06-15 18:59:49.525260
> ```
>
> Does that work for you?
>
> Cheers,
> /Tobias
>
> Am 15.06.2015 um 17:18 schrieb Raffaele Bianco:
> > Hi,
> >
> > I need run a background process either periodically or triggered
> by a
> > separate component. I figured that the easier way to go about is:
> >
> > def __iter__(self):
> > yield self.subscribe(self.run, "
a.topic.name <
http://a.topic.name>")
> >
> > while True:
> > yield self.publish("
a.topic.name <
http://a.topic.name>")
> > yield sleep(5)
> >
> >
> > Unfortunately I've just discovered that after around 15 seconds the
> > 'wamp.session.on_leave' session is called and a separate
> component will
> > change global state that causes my background process to fail.
> >
> > I tried playing with the components->transport->timeout settings
> but it
> > doesn't seem to work (also the default is 10 seconds and I get a
> > on_leave after 15 secs).
> >
> > Any clue?
> >
> > Thanks,
> > Raffaele
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Crossbar" group.
> > To unsubscribe from this group and stop receiving emails from it,
> send
> > an email to
crossbario+...@googlegroups.com <javascript:>
> > <mailto:
crossbario+...@googlegroups.com <javascript:>>.
> <javascript:>
> > <mailto:
cross...@googlegroups.com <javascript:>>.
> <
https://groups.google.com/d/msgid/crossbario/7907cfdd-936a-44da-81f1-a6d02c67ee8c%40googlegroups.com?utm_medium=email&utm_source=footer
> <
https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Crossbar" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
crossbario+...@googlegroups.com
> <mailto:
crossbario+...@googlegroups.com>.
>
https://groups.google.com/d/msgid/crossbario/c915873f-330c-43ea-9832-48b1e0cb123b%40googlegroups.com
> <
https://groups.google.com/d/msgid/crossbario/c915873f-330c-43ea-9832-48b1e0cb123b%40googlegroups.com?utm_medium=email&utm_source=footer>.