'Publish' not happening until script is done

27 views
Skip to first unread message

sscirrus

unread,
Jan 10, 2018, 7:01:47 AM1/10/18
to Autobahn
I have a Python script that sometimes runs a process that lasts ~5-60 seconds. During this time, all its calls to session.publish() are ignored until the script is done. As soon as the time is up, all messages are published in a flood.

I have corroborated this by opening the Crossbar.io router in debug mode, and it shows logs corresponding to the published messages after the time is over (not during the run as expected).

My script is long, complex and includes a combined frontend and backend for Crossbar/Twisted/Autobahn. I feel I would risk misreporting if I tried to condense and include it.

What possible reason is there for publish to not happen instantaneously?

David Ford

unread,
Jan 10, 2018, 10:35:36 PM1/10/18
to autob...@googlegroups.com
your script isn't performing asynchronously

--
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.
To post to this group, send email to autob...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/autobahnws/5c04c639-d1d7-45ca-81cd-994dc9abe84e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

sscirrus

unread,
Jan 11, 2018, 1:03:48 AM1/11/18
to Autobahn
Thanks for your message.

Here below is a specific example. How can I get the two `publish` commands in my_script() to publish 2s apart as the code suggests?


@component.on_join
@inlineCallbacks
def join(session, details):
    print("joined {}: {}".format(session, details))

         def publish(value):
        session.publish(u'com.asdf.ghjk', {"value": value})
    pass

    def my_script(thing):
        publish('TEST 1')
        sleep(2)
        publish('TEST 2')

    try:
        yield session.register(my_script, u'com.asdf.ghjk')
    except Exception as e:
        print("could not register procedure: {0}".format(e))


David Ford

unread,
Jan 14, 2018, 9:16:06 PM1/14/18
to autob...@googlegroups.com
is your tool based on asyncio or twisted?

sscirrus

unread,
Jan 14, 2018, 11:14:54 PM1/14/18
to Autobahn
Twisted. With Crossbar and Autobahn.

David Ford

unread,
Jan 15, 2018, 3:04:10 AM1/15/18
to autob...@googlegroups.com
look at reactor.callLater(secs, callback, ...)

sscirrus

unread,
Jan 17, 2018, 6:28:55 PM1/17/18
to Autobahn
Thanks.
Reply all
Reply to author
Forward
0 new messages