update to avoid not reusing session ids

This commit is contained in:
Blake Harnden 2019-12-13 10:54:42 -08:00
parent 819954a695
commit 358985d129

View file

@ -5,7 +5,6 @@ import signal
import sys import sys
import core.services import core.services
from core.emulator.emudata import IdGen
from core.emulator.session import Session from core.emulator.session import Session
from core.services.coreservices import ServiceManager from core.services.coreservices import ServiceManager
@ -49,7 +48,6 @@ class CoreEmu:
self.config = config self.config = config
# session management # session management
self.session_id_gen = IdGen()
self.sessions = {} self.sessions = {}
# load services # load services
@ -79,7 +77,6 @@ class CoreEmu:
:return: nothing :return: nothing
""" """
logging.info("shutting down all sessions") logging.info("shutting down all sessions")
self.session_id_gen.id = 0
sessions = self.sessions.copy() sessions = self.sessions.copy()
self.sessions.clear() self.sessions.clear()
for _id in sessions: for _id in sessions:
@ -96,11 +93,9 @@ class CoreEmu:
:rtype: EmuSession :rtype: EmuSession
""" """
if not _id: if not _id:
while True: _id = 1
_id = self.session_id_gen.next() while _id in self.sessions:
if _id not in self.sessions: _id += 1
break
session = _cls(_id, config=self.config) session = _cls(_id, config=self.config)
logging.info("created session: %s", _id) logging.info("created session: %s", _id)
self.sessions[_id] = session self.sessions[_id] = session