【问题标题】:Pubnub with py2app throwing [Errno 20] Not a directory带有 py2app 的 Pubnub 抛出 [Errno 20] 不是目录
【发布时间】:2014-08-14 05:07:10
【问题描述】:

我有一个简单的 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()

【问题讨论】:

  • 所以这确实很奇怪!我已将您的代码输出粘贴在下面。看起来很健康是吗?
  • 谢谢。但是当我直接运行程序时,我没有遇到任何问题。只有当我用 py2app 打包然后运行生成的应用程序时才会出现问题。
  • 如果您仍然遇到问题,请发送电子邮件至 support@pubnub.com,我们将在 GIFFY 中解决它们!
  • 谢谢。我向 pubnub 支持发送了一封邮件。

标签: python py2app pyobjc pubnub


【解决方案1】:

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

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

看起来像这样:

PIP FREEZE如下:

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

PubNub PIP Freeze 的图片截图:

【讨论】:

    猜你喜欢
    • 2016-11-18
    • 1970-01-01
    • 2021-09-19
    • 2021-04-09
    • 2014-08-21
    • 2013-08-02
    • 1970-01-01
    • 1970-01-01
    • 2015-08-04
    相关资源
    最近更新 更多