我結束了具有各GUI劑創建/ tmp下一個數據報套接字,然後launchdaemon反過來將消息發送到每一個和清理陳舊插口:
SOCKET_DIR = "/tmp"
SOCKET_NAME = "se.gu.it.dafgu_migration_status"
status_socket = None
def set_status_menu(status, message):
global status_socket
try:
if status_socket is None:
status_socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
if status_socket is not None:
message = serializePlist({
"DAFGUMigrationStatus": status,
"DAFGUMigrationMessage": message,
})
for item in os.listdir(SOCKET_DIR):
if item.startswith(SOCKET_NAME):
socket_path = os.path.join(SOCKET_DIR, item)
logging.debug("Sending message to %s" % socket_path)
try:
status_socket.sendto(message, socket_path)
except socket.error, e:
if e[0] == errno.ECONNREFUSED:
logging.info("Removing stale socket %s" % socket_path)
os.unlink(socket_path)
else:
logging.warn("Sending to %s failed: %s" % (socket_path, e))
except BaseException, e:
logging.debug("Unhandled exception when updating status menu: %s" % e)
充分執行,可以發現在github上: