Pubnub与py2app投掷[Errno 20]不是目录

时间:2014-08-14 05:07:10

标签: python py2app pyobjc pubnub

我有一个简单的Pubnub代码,我将其发布到一个频道,然后使用该频道中的消息。当我将它作为独立程序运行时,我的工作方式应该如此。但是,如果我使用py2app打包它,我会收到以下错误:

[Errno 20] Not a directory

以下是代码:

from Pubnub import Pubnub
from threading import Thread
from hashlib import md5

def trace(msg):
    from Foundation import NSLog
    NSLog(str(msg))

# Class to be called in a seperate thread
class Subscriber(Thread):

    def __init__(self, func_obj, channel_name):
        ''' Constructor. '''
        Thread.__init__(self)
        self.channel_name = channel_name
        self.func_obj = func_obj
        trace("thread init ")

    def run(self):
        trace("run")
        self.func_obj(self.channel_name)


class ManageSubscription(object):

    def __init__(self):
        self.pusher_obj = Pusher()

    def publish_to_channel(self, channel_name, message):
        self.pusher_obj.publish(channel_name, message)

    def subscribe_to_channel(self, channel_name):
        trace("subscribe to channel1")
        try:
            self.pusher_obj.subscribe(channel_name)
        except Exception as e:
            trace(e)

    def unsubscribe_to_channel(self, channel_name):
        trace("Unsubscribe to channel")
        self.pusher_obj.disconnect()


class Pusher(object):

    pubnub = None

    def __init__(self):
        if not Pusher.pubnub:
            Pusher.pubnub = Pubnub(PUBNUB_KEYS['publisher'],
                                   PUBNUB_KEYS['subscriber'],
                                   PUBNUB_KEYS['secret'],
                                   ssl_on=True,
                                   origin=PUBNUB_KEYS['domain'])

    @staticmethod
    def error(msg):
        # import osx.tray as tray
        trace('Came to error' + msg)
        # trace(msg)
        # tray.notify.notify('Deleted', 'subtitle', 'description text', 'http://google.com')
        # trace(msg)
        return True

    @staticmethod
    def connect(msg):
        # import osx.tray as tray
        trace('Came to connect')
        # trace(msg)
        # tray.notify.notify('Deleted', 'subtitle', 'description text', 'http://google.com')
        # trace(msg)
        return True

    @staticmethod
    def get_message(msg, msg1):
        # import osx.tray as tray
        trace('Came to callback')
        trace(msg)
        trace(msg1)
        # tray.notify.notify('Deleted', 'subtitle', 'description text', 'http://google.com')
        # trace(msg)
        return True

    @staticmethod
    def subscribe(channel_name):
        trace("Came to subscriber")
        pp_channel = 'channel_id_goes_here'
        Pusher.pubnub.subscribe(channels=pp_channel, callback=Pusher.get_message, connect=Pusher.connect, error=Pusher.error)
        trace('done')

    @staticmethod
    def publish(channel_name, message):
        trace("Came to publish")
        Pusher.pubnub.publish('channel_id_goes_here', message, callback=Pusher.connect, error=Pusher.error)
        trace('done')


subscription_manager = ManageSubscription()
subscription_manager.publish_to_channel('channel_id_goes_here', 'I published this')
thread1 = Subscriber(subscription_manager.subscribe_to_channel, 'channel_id_goes_here')
thread1.start()

1 个答案:

答案 0 :(得分:0)

我运行你的程序,我收到以下输出:

2014-08-13 22:26:57.190 Python[10435:1107] Came to publish
2014-08-13 22:26:57.201 Python[10435:1107] done
2014-08-13 22:26:57.201 Python[10435:1107] thread init 
2014-08-13 22:26:57.202 Python[10435:301b] run
2014-08-13 22:26:57.202 Python[10435:301b] subscribe to channel1
2014-08-13 22:26:57.203 Python[10435:301b] Came to subscriber
2014-08-13 22:26:57.203 Python[10435:301b] done
2014-08-13 22:26:57.337 Python[10435:2b2f] Came to connect
2014-08-13 22:26:57.350 Python[10435:3203] Came to connect

看起来像这样:

PubNub Python PIP Package Demo Code

PIP FREEZE如下:

pip freeze | grep pubnub
pubnub==3.5.2
pubnub-console==3.5.0

PubNub PIP Freeze的图片截图:

PubNub pip freeze console output