'A Session object is created which is configured with the Tribler configuration object.
Only a single session instance can exist at a time in a process.
:param config: a TriblerConfig object or None, in which case we
look for a saved session in the default location (state dir). If
we can\'t find it, we create a new TriblerConfig() object to
serve as startup config. Next, the config is saved in the directory
indicated by its \'state_dir\' attribute.
:param ignore_singleton: for testing purposes only. Enables the existence of multiple
Session instances.
:param autoload_discovery: only false in the Tunnel community tests'

def __init__(self, config=None, ignore_singleton=False, autoload_discovery=True):

    addObserver(self.unhandled_error_observer)
    patch_crypto_be_discovery()
    if (not ignore_singleton):
        if Session.__single:
            raise RuntimeError('Session    is    singleton')
        Session.__single = self
    self._logger = logging.getLogger(self.__class__.__name__)
    self.ignore_singleton = ignore_singleton
    self.session_lock = NoDispersyRLock()
    self.config = (config or TriblerConfig())
    self.get_ports_in_config()
    self.create_state_directory_structure()
    if (not config.get_megacache_enabled()):
        config.set_torrent_checking_enabled(False)
    self.selected_ports = config.selected_ports
    self.init_keypair()
    self.lm = TriblerLaunchMany()
    self.notifier = Notifier()
    self.sqlite_db = None
    self.upgrader = None
    self.dispersy_member = None
    self.autoload_discovery = autoload_discovery
