コード例 #1
0
ファイル: start_core.py プロジェクト: overflw/tribler
async def core_session(config: TriblerConfig, components: List[Component]):
    session = Session(config, components, failfast=False)
    signal.signal(signal.SIGTERM, lambda signum, stack: session.shutdown_event.set)
    session.set_as_default()

    await session.start()

    # If there is a config error, report to the user via GUI notifier
    if config.error:
        session.notifier.notify(NTFY.REPORT_CONFIG_ERROR.value, config.error)

    # SHUTDOWN
    await session.shutdown_event.wait()
    await session.shutdown()

    if not config.gui_test_mode:
        session.notifier.notify(NTFY.TRIBLER_SHUTDOWN_STATE.value, "Saving configuration...")
        config.write()
コード例 #2
0
def test_session_context_manager(loop, tribler_config):  # pylint: disable=unused-argument
    session1 = Session(tribler_config, [])
    session2 = Session(tribler_config, [])
    session3 = Session(tribler_config, [])

    with pytest.raises(SessionError, match="Default session was not set"):
        Session.current()

    session1.set_as_default()
    assert Session.current() is session1

    with session2:
        assert Session.current() is session2
        with session3:
            assert Session.current() is session3
        assert Session.current() is session2
    assert Session.current() is session1

    Session.unset_default_session()

    with pytest.raises(SessionError, match="Default session was not set"):
        Session.current()