Beispiel #1
0
 def _init_glib_loop(self):
     self._glib_context = GLib.MainContext()
     self._glib_loop = GLib.MainLoop(self._glib_context)
     self._glib_thread = threading.Thread(target=self._main_loop,
                                          name="GStreamer driver main loop",
                                          daemon=True)
     self._glib_thread.start()
Beispiel #2
0
    def __init__(self, glib_context=None, gtk=False, application=None):

        assert (glib_context is not None) + bool(gtk) + (application
                                                         is not None) <= 1

        self._gtk = gtk
        self._application = application

        if gtk or self._application is not None:
            self._context = GLib.main_context_default()
        else:
            self._context = glib_context if glib_context else GLib.MainContext(
            )

        self._readers = {}
        self._writers = {}
        self._sighandlers = {}
        self._chldhandlers = {}
        self._handlers = set()
        self._ready = collections.deque()
        self._wakeup = None
        self._will_dispatch = False
        self._loop_implem = None
        self._interrupted = False

        super(BaseGLibEventLoop, self).__init__()

        # install a default handler for SIGINT
        # in the default context
        if self._context == GLib.main_context_default():
            assert hasattr(self, "_default_sigint_handler"
                           ), "Must call BaseGLibEventLoop.init_class() first"
            self._default_sigint_handler.attach(self)
Beispiel #3
0
    def on_transport(self, beacon):
        self.change_status(Garmin.Status.CONNECTED)

        while True:
            if self.timeout_source:
                self.timeout_source = None
                return

            while self.funcs:
                f, cb, args = self.funcs.pop(0)
                ret = f(self, *args)
                # run in ui thread
                GLib.idle_add(lambda: cb(ret))

            # we've run out of things to do for now. set a timer so we don't
            # disconnect immediately.

            # use a new context as we don't want to get mixed up with the
            # other mainloop currently running
            context = GLib.MainContext()
            self.loop = GLib.MainLoop(context)

            def timeout_cb(data=None):
                self.loop.quit()
                self.loop = None

            self.timeout_source = GLib.timeout_source_new_seconds(5)
            self.timeout_source.set_callback(timeout_cb)
            self.timeout_source.attach(context)
            self.loop.run()
Beispiel #4
0
def test_policy_new_event_loop_with_default_set(policy: GLibEventLoopPolicy):
    context = GLib.MainContext()
    context.push_thread_default()

    new_loop = policy.new_event_loop()

    assert new_loop.context == context
Beispiel #5
0
    def __init__(self, *, context=None, application=None):
        self._context = context or GLib.MainContext()
        self._application = application
        self._running = False

        if application is None:
            self._mainloop = GLib.MainLoop(self._context)
        super().__init__()
Beispiel #6
0
 def start(self):
     self._context = GLib.MainContext()
     self._server.attach(self._context)
     self._mainloop = GLib.MainLoop.new(self._context, False)
     self._thread = Thread(target=self._loop, daemon=True)
     self._thread.start()
     self._logger.info("Gstreamer RTSP Server Started on port: {}".format(
         self._port))
Beispiel #7
0
 def __init__(self):
     super().__init__()
     if isinstance(threading.current_thread(), threading._MainThread):
         self._context = GLib.main_context_default()
     else:
         self._context = GLib.MainContext()
     self.loop = GLib.MainLoop(self._context)
     self.pending_events = set()
Beispiel #8
0
def test_policy_set_event_loop_with_wrong_context(policy: GLibEventLoopPolicy):
    from aioglib import GLibEventLoop

    new_context = GLib.MainContext()
    bad_loop = GLibEventLoop(new_context)

    with raises(ValueError):
        policy.set_event_loop(bad_loop)
Beispiel #9
0
    def setUp(self):
        self.idlequeue_thread = IdleQueueThread()
        self.idlequeue_thread.start()
        self.main_context = GLib.MainContext()
        self.main_context.push_thread_default()
        self.main_loop = GLib.MainLoop(self.main_context)

        self.iq = self.idlequeue_thread.iq
        self._reset()
        self.resolver = None
Beispiel #10
0
    def test_is_destroyed_simple(self):
        s = GLib.Source()

        self.assertFalse(s.is_destroyed())
        s.destroy()
        self.assertTrue(s.is_destroyed())

        c = GLib.MainContext()
        s = GLib.Source()
        s.attach(c)
        self.assertFalse(s.is_destroyed())
        s.destroy()
        self.assertTrue(s.is_destroyed())
Beispiel #11
0
    def __init__(self, context=None):
        self._handlers = set()

        self._accept_futures = {}
        self._context = context or GLib.MainContext()
        self._selector = self
        self._transports = weakref.WeakValueDictionary()
        self._readers = {}
        self._writers = {}

        self._channels = weakref.WeakValueDictionary()

        _BaseEventLoop.__init__(self)
        GLibBaseEventLoopPlatformExt.__init__(self)
Beispiel #12
0
    def test_main_context(self):
        # constructor
        context = GLib.MainContext()
        self.assertTrue(context.is_owner() in [True, False])
        self.assertFalse(context.pending())
        self.assertFalse(context.iteration(False))

        # GLib API
        context = GLib.MainContext.default()
        self.assertTrue(context.is_owner() in [True, False])
        self.assertTrue(context.pending() in [True, False])
        self.assertTrue(context.iteration(False) in [True, False])

        # backwards compatible API
        context = GLib.main_context_default()
        self.assertTrue(context.is_owner() in [True, False])
        self.assertTrue(context.pending() in [True, False])
        self.assertTrue(context.iteration(False) in [True, False])
Beispiel #13
0
    def execute_new_loop(self, signal):
        """Starts the new event loop and pass `signal` in it.

        This is required for processing a modal screens.

        :param signal: signal passed to the new event loop
        :type signal: `AbstractSignal` based class
        """
        super().execute_new_loop(signal)

        if self._force_quit:
            return

        new_context = GLib.MainContext()
        new_loop = GLib.MainLoop(new_context)
        loop_data = EventLoopData(new_loop)
        self._event_loops.append(loop_data)

        self.enqueue_signal(signal)
        new_loop.run()
Beispiel #14
0
 def test_main_loop_with_context(self):
     context = GLib.MainContext()
     ml = GLib.MainLoop(context)
     self.assertFalse(ml.is_running())
     self.assertEqual(ml.get_context(), context)
Beispiel #15
0
	def iteration(): # {{{
		'''Do a single iteration of the GLib main loop.  Do not block.
		@return None.'''
		GLib.MainContext().iteration(False)
Beispiel #16
0
 def f():
     c = GLib.MainContext()
     s = GLib.Source()
     s.attach(c)
     return s
Beispiel #17
0
 def setUp(self):
     self.main_context = GLib.MainContext()
     self.main_context.push_thread_default()
     self.main_loop = GLib.MainLoop(self.main_context)
     self._reset()
     self.resolver = None
Beispiel #18
0
def loop():
    from aioglib._loop import GLibEventLoop
    return GLibEventLoop(GLib.MainContext())