【发布时间】: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