Threading: sendMessage at onMessage

96 views
Skip to first unread message

Alejandro Torrado

unread,
Mar 5, 2012, 1:28:43 PM3/5/12
to Autobahn
Hi, I'm implementing Autobahn with user actions handled in web,
triggered by the back-end in python. Because of the nature of user
actions, these are executed in separated threads for separated users.

The code looks something like this:

def onMessage(self, msg, binary):
class ActionThread(CThread):
def __init__(self, protocol):
self.protocol = protocol
def run(self):
.......
print 1
self.protocol.sendMessage("something")
print 2
.......
ActionThread(self).start()

Doing this, the message "something" isn't delivered even though 1 and
2 are printed to console. Then, when the user sends another message to
the server, the first message arrives.

How can I fix this? Thanks!

Tobias Oberstein

unread,
Mar 5, 2012, 4:26:35 PM3/5/12
to autob...@googlegroups.com, Alejandro Torrado
try:

reactor.callFromThread(self.protocol.sendMessage, "something")

see:

https://github.com/oberstet/Autobahn/issues/90

and search for similar posts on this list or

checkout the Twisted docs on callFromThread etc.

Alejandro Torrado

unread,
Mar 6, 2012, 8:38:47 AM3/6/12
to autob...@googlegroups.com, Alejandro Torrado
Thanks a lot! Worked like a charm!
Reply all
Reply to author
Forward
0 new messages