最后调查发现是bluetman 惹得祸

贴上他的守护程序,以后也可以写一个

#! /usr/bin/python3

from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from __future__ import unicode_literals

import sys
import os.path
import os
import signal
import dbus
from dbus.mainloop.glib import DBusGMainLoop
from blueman.Constants import *
import gi
gi.require_version("Gtk", "3.0")
gi.require_version('Notify', '0.7')
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GObject
from gi.repository import Notify
try: import __builtin__ as builtins
except ImportError: import builtins

DBusGMainLoop(set_as_default=True)

#support running uninstalled
_dirname = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
if os.path.exists(os.path.join(_dirname, "CHANGELOG.md")):
    sys.path.insert(0, _dirname)

from blueman.Functions import *

from blueman.main.DbusService import DbusService

import blueman.plugins.applet
from blueman.plugins.AppletPlugin import AppletPlugin
from blueman.plugins.BasePlugin import BasePlugin

import blueman.bluez as Bluez

from blueman.main.SignalTracker import SignalTracker

from blueman.main.PluginManager import PersistentPluginManager

# Workaround introspection bug, gnome bug 622084
signal.signal(signal.SIGINT, signal.SIG_DFL)
signal.signal(signal.SIGTERM, signal.SIG_DFL)

class BluemanApplet(object):
    def __init__(self):
        setup_icon_path()
        if not Notify.init("Blueman"):
            dprint("Error: Failed to initialize libnotify")

        check_single_instance("blueman-applet")

        self.Manager = None
        self.DbusSvc = DbusService("org.blueman.Applet", "/")
        self.Signals = SignalTracker()

        self.Plugins = PersistentPluginManager(AppletPlugin, blueman.plugins.applet, self)
        self.Plugins.Load()

        self.Plugins.Run("on_plugins_loaded")

        self.bus = dbus.SystemBus()
        self.bus.watch_name_owner("org.bluez", self.on_dbus_name_owner_change)

        Bluez.Adapter().handle_signal(self.on_adapter_property_changed, 'PropertyChanged', path_keyword='path')

        Gtk.main()


    def manager_init(self):
        try:

            self.Signals.DisconnectAll()
            self.Manager = Bluez.Manager()
            self.Plugins.Run("on_manager_state_changed", True)

            self.Signals.Handle("bluez", self.Manager, self.on_adapter_removed, "AdapterRemoved")
            self.Signals.Handle("bluez", self.Manager, self.on_adapter_added, "AdapterAdded")

        except dbus.exceptions.DBusException as e:
            dprint(e)
            self.manager_deinit()
            dprint("Bluez DBus API not available. Listening for DBus name ownership changes")

    def manager_deinit(self):
        self.Signals.DisconnectAll()
        self.Manager = None
        self.Plugins.Run("on_manager_state_changed", False)

    def on_dbus_name_owner_change(self, owner):
        dprint("org.bluez owner changed to", owner)
        if owner == "":
            self.manager_deinit()
        elif self.Manager is None:
            self.manager_init()

    def on_adapter_property_changed(self, key, value, path):
        self.Plugins.Run("on_adapter_property_changed", path, key, value)

    def on_adapter_added(self, path):
        dprint("Adapter added ", path)

        def on_activate():
            dprint("Adapter activated")
            self.Plugins.Run("on_adapter_added", path)

        adapter = Bluez.Adapter(path)
        wait_for_adapter(adapter, on_activate)

    def on_adapter_removed(self, path):
        dprint("Adapter removed ", path)
        self.Plugins.Run("on_adapter_removed", path)


set_proc_title()
BluemanApplet()
posted on 2018-03-08 22:12  HDU李少帅  阅读(212)  评论(0编辑  收藏  举报