VM Session occasionally freezing

So occasionally the VM session for a PI for our HMI freezes.

I already know IT has me in their scope to blame. So I jumping on it. at the bottom is a pic of the console log around the time it happened

Below are 3 sections of code which have been added recently. (Yes, I know they have to be cleaned up and consolidated, which I am working on but I don’t think that affects this.) But we had them freezing up prior to this code.

I’ve been working on cleaning up errors Ive seen with tags not writing etc…

below is the code which executes in a client timer script every 1s

# Grabs timer value and writes it to variable.
Timer = system.tag.read("[Client]BadgeSystem/TimerValue")
# If timer value equals 3 minutes (180 seconds) log user out and switch to logged off page.
if Timer.value == 180:
	system.nav.swapTo('Logged Off')
	system.security.switchUser("plc", "plc")
	system.tag.writeToTag("[Client]BadgeSystem/DisplayCountdown", 0)
	system.tag.writeToTag("[Client]BadgeSystem/TimerValue", 0)
	system.tag.writeToTag("[Client]BadgeSystem/TimerRunning", 0)

below is the logout button code

system.nav.swapTo('Logged Off')
system.security.switchUser("plc", "plc")
system.tag.writeToTag("[Client]BadgeSystem/DisplayCountdown", 0)
system.tag.writeToTag("[Client]BadgeSystem/TimerRunning", 0)
system.tag.writeToTag("[Client]BadgeSystem/TimerValue", 0)

and below is the code to access any main window

# This script controls the badge access feature
# It allows the user to log into a page, or 
# redirects them to the invalid login, or access denied page
# it also resets and sets the timer to log out user after set time 

#Displays keyboard to scan badge or enter emergency use password
password = system.gui.showTouchscreenKeyboard("Scan Badge or Enter Emergency Password")

# opens and scans user table to cross reference password to username to provide login credentials.
system.nav.openWindow("Main Windows/TableImport")
window = system.gui.getWindow("Main Windows/TableImport")
data = window.rootContainer.getComponent("User Table").data
system.nav.closeWindow("Main Windows/TableImport")
user_name = ""

for row in range(data.rowCount):
	index_row = data.getValueAt(row, 3)
	if index_row == password:
		user_name = data.getValueAt(row, 1)
		break

# Allows successful access to page if user role has security clearance, enable and resets timer
# sends them to access denied page if user does not have valid security clearance
success = system.security.switchUser(user_name, password)
roles = system.security.getRoles()
if u'Administrator' in roles or u'LVL_2' in roles or u'LVL_4' in roles:
	system.nav.closeWindow("Logged Off")
	system.nav.swapTo('Powder Main')
	system.tag.writeToTag("[Client]BadgeSystem/TimerValue", 0)
	system.tag.writeToTag("[Client]BadgeSystem/DisplayCountdown", 1)
	system.tag.writeToTag("[Client]BadgeSystem/TimerRunning", 1)
else:
	system.nav.closeWindow("Logged Off")
	system.nav.swapTo('Access Denied')
	system.tag.writeToTag("[Client]BadgeSystem/TimerValue", 0)
	system.tag.writeToTag("[Client]BadgeSystem/DisplayCountdown", 0)
	system.tag.writeToTag("[Client]BadgeSystem/TimerRunning", 0)
    
# Sends user to failed login page if badge scan does not work
if not success:
	system.nav.closeWindow("Logged Off")
	system.nav.swapTo('Failed Login')
	system.tag.writeToTag("[Client]BadgeSystem/TimerValue", 0)
	system.tag.writeToTag("[Client]BadgeSystem/DisplayCountdown", 0)
	system.tag.writeToTag("[Client]BadgeSystem/TimerRunning", 0)

console log around time of issue

Any help would be greatly appreciated if you see anything wrong. and have any tips.
thank you!