Rhinoscript Python3 Queue and Pubnub

304 views Asked by At

So recently I've been trying to install new modules into RhinoScript python using pip install --target. The project I am working on is where one computer will capture midi from a piano I have setup with pygame.midi and then transmit that midi data via pubnub to a computer running a custom rhinoscript plugin which would interpret the data.

Here is my PubNub interface I half copied half wrote

from pubnub.pubnub import PubNub
from pubnub.pnconfiguration import PNConfiguration
from pubnub.callbacks import SubscribeCallback
from pubnub.enums import PNOperationType, PNStatusCategory

pnconfig = PNConfiguration()

pnconfig.subscribe_key = 'mysubkey'
pnconfig.publish_key = 'mypubkey'

pubnub = PubNub(pnconfig)

class MySubscribeCallback(SubscribeCallback):
    def status(self, pubnub, status):
        pass
        # The status object returned is always related to subscribe but could contain
        # information about subscribe, heartbeat, or errors
        # use the operationType to switch on different options
        if status.operation == PNOperationType.PNSubscribeOperation \
                or status.operation == PNOperationType.PNUnsubscribeOperation:
            if status.category == PNStatusCategory.PNConnectedCategory:
                print(status)
                # This is expected for a subscribe, this means there is no error or issue whatsoever
            elif status.category == PNStatusCategory.PNReconnectedCategory:
                pass
                # This usually occurs if subscribe temporarily fails but reconnects. This means
                # there was an error but there is no longer any issue
            elif status.category == PNStatusCategory.PNDisconnectedCategory:
                pass
                # This is the expected category for an unsubscribe. This means there
                # was no error in unsubscribing from everything
            elif status.category == PNStatusCategory.PNUnexpectedDisconnectCategory:
                pass
                # This is usually an issue with the internet connection, this is an error, handle
                # appropriately retry will be called automatically
            elif status.category == PNStatusCategory.PNAccessDeniedCategory:
                pass
                # This means that PAM does allow this client to subscribe to this
                # channel and channel group configuration. This is another explicit error
            else:
                pass
                # This is usually an issue with the internet connection, this is an error, handle appropriately
                # retry will be called automatically
        elif status.operation == PNOperationType.PNSubscribeOperation:
            # Heartbeat operations can in fact have errors, so it is important to check first for an error.
            # For more information on how to configure heartbeat notifications through the status
            # PNObjectEventListener callback, consult <link to the PNCONFIGURATION heartbeart config>
            if status.is_error():
                pass
                # There was an error with the heartbeat operation, handle here
            else:
                pass
                # Heartbeat operation was successful
        else:
            pass
            # Encountered unknown status type

    def presence(self, pubnub, presence):
        pass  # handle incoming presence data

    def message(self, pubnub, message):
        print(message.message)

pubnub.add_listener(MySubscribeCallback())

def publish_callback(result, status):
    pass
    # Handle PNPublishResult and PNStatus


def publishAMessage():
    while True:
        messageinput = input("what would you like to say:  ")
        pubnub.publish().channel('zanescustomkey').message([messageinput]).async(publish_callback)


pubnub.subscribe().channels('zanescustomkey').execute()


print('reached the end')

When you put this into RhinoScript, you get import errors

Message: No module named queue
Traceback:
line 6, in <module>, "C:\Program Files\Rhinoceros 5 (64-bit)\Plug-ins\IronPython\Lib\pubnub\pubnub.py"
line 2, in <module>, "C:\Users\zanem\OneDrive\Documents\PubNub\pythontest.py"

On the IronPython website, which essentially is what RhinoScript is, they say they support mulitprocessors. Do any of you here know how I would go about importing queue into Rhinoscript, it seems like there is nothing written about this in PubNub or Rhinoscript docs.

0

There are 0 answers