0

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.

Craig Conover
  • 4,710
  • 34
  • 59
  • It looks perhaps like an issue with the `six` module (Py 2/3 compatibility) and IronPython. Here's the line from pubnub that's causing the issue: https://github.com/pubnub/python/blob/08866c5f4a68e1e29457e16197ad5bd8d580a9a1/pubnub/pubnub.py#L6 – DBrowne Aug 30 '17 at 00:36
  • It looks like `six` module doesn't play nice with IronPython in general. You may need to make your own fork of the pubnub library and swap out all the usages of `six` with the built-in python equivalent. i.e. the line I linked would become: `from Queue import Queue, Empty`. – DBrowne Aug 30 '17 at 00:48
  • Relevant: https://stackoverflow.com/questions/35162177/its-possible-to-use-requests-in-ironpython-2-7-5 – DBrowne Aug 30 '17 at 00:52
  • Do you know the 'non six' equivalent of this: `from .packages.six.moves.http_client import ( IncompleteRead as httplib_IncompleteRead )` By the way, the suggestion you had about import Queue worked well, this is the next error it is giving me. – Zane Mechem Aug 30 '17 at 02:15
  • Rpyc looks like a good solution, they will be on the same LAN. I'm going to look into that. Thank you for the help. – Zane Mechem Aug 30 '17 at 02:34
  • Sorry, I deleted that last comment because I had thought you were asking for alternatives to pubnub. Yes I think that you can definitely achieve what you want to without pubnub. RPyC allows you to to totally remote control the remote python interpreter which gives you a lot of freedom. Another more lightwweight option is that you would write a TCP Socket server (https://docs.python.org/2.7/library/socketserver.html) to run on the Rhino end and send TCP packets from your client PC to trigger execution of certain commands (https://docs.python.org/2.7/howto/sockets.html). – DBrowne Aug 30 '17 at 02:45

0 Answers0