Re: [Maya-Python] call function inside running websocket thread

145 views
Skip to first unread message

Justin Israel

unread,
Dec 17, 2015, 3:24:22 PM12/17/15
to Python Programming for Autodesk Maya
Hey Ben,

I haven't used this websocket library, so I don't know much about how it works, other than a high level guess about it being mostly the same as any other server with an event loop and connection handling. 

You are correct that once you call run_forever() you enter into an event loop so that the websocket library can poll for connections. When you say you want to execute an external function... who is initiating this? Is it a connected client that wants to call an external function? When is this external function triggered? I wasn't sure if you meant that the external function was an RPC call for clients, or that you have some other operation you want to run right after you have set up your websocket server.


On Fri, Dec 18, 2015 at 1:56 AM Ben Hearn <ben....@starbreeze.com> wrote:
Hello all,

I have been setting up some communication between applications using websockets in python. The module is websocket-client.

The comms is great, the messages are sent and received which is what I need I have hit a snag though. I have a function inside my script that needs to be called from Maya whenever we need it to.

When the websocket is set up I call run_forever to keep the socket open for future comms. The problem is I cannot jump out of the run_forever loop so that the executeExternal function can be called.

I have read up on Queues but am stumped with how to use properly or if I should in this case?

The idea is that I will eventually call the main function for the websocket inside a thread from Maya like so:

# Inside user setup or wherever in the code base
import ws
import threading

ws = threading.Thread(target=ws.main)
ws.start()

# Call execute external function later from wherever in the code base

Code is below:

Cheers,

Ben

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/b3d2be9c-5374-4ec2-9924-c2576dc47dc1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages