Threading: sendMessage at onMessage

#1

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!

0 Likes

#2

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.

···

Am 05.03.2012 19:28, schrieb Alejandro Torrado:

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!

0 Likes

#3

Thanks a lot! Worked like a charm!

···

El lunes 5 de marzo de 2012 18:26:35 UTC-3, tgo escribió:

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.

Am 05.03.2012 19:28, schrieb Alejandro Torrado:

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!

0 Likes