Commit 117dca61 authored by Guillaume Garrigos's avatar Guillaume Garrigos
Browse files

Debug fake active user

There is some inconsistency between how printing, windows, unix and multiprocessing work... calling a process from a loaded module doesn't work so we call it directly from the notebook
parent 7f90f360
......@@ -29,8 +29,10 @@
"outputs": [],
"source": [
"# N'exécuter qu'une seule fois\n",
"import mybinder \n",
"mybinder.start_session()"
"import multiprocessing\n",
"import mybinder\n",
"if __name__ == '__main__':\n",
" multiprocessing.Process(target=mybinder.start_session).start()"
]
},
{
......
......@@ -2,33 +2,29 @@ import os, time, datetime
import multiprocessing
SESSION_LENGTH = 90 # in minutes
USED_TOKEN = False # makes sure we call the dummy worker only once
USED_TOKEN = multiprocessing.Value('i', 0) # a global variable. makes sure we call the dummy worker only once
def clock():# ensures time is set to Paris wherever is run the notebook
def clock():# ensures time is set to Paris (UTC+1) wherever is run the notebook
current_time = datetime.datetime.utcnow() + datetime.timedelta(hours=1)
return current_time.strftime('%X')
def dummy_worker():
# warn the user to not run twice
#print("Session de " + str(SESSION_LENGTH) + " minutes commençant à " + clock() + ". Ne pas interrompre, ni relancer une deuxième fois.")
pause = 5
chrono = 0
nb_sleeps = int(SESSION_LENGTH/pause)
for i in range(nb_sleeps):
time.sleep(pause*60)
chrono = chrono + pause
print('Session ouverte depuis '+str(chrono)+' minutes', end="\r")
print("Session de " + str(SESSION_LENGTH) + " minutes terminée à " + clock() + ".")
print("Le serveur s'arrêtera après 10 minutes d'inactivité")
return
def start_session():
global USED_TOKEN
if USED_TOKEN:
if USED_TOKEN.value:
print("Vous ne pouvez maintenir une session ouverte qu'une seule fois")
else:
USED_TOKEN = True # makes sure the dummy woker is called only once
# makes sure the dummy woker is called only once
USED_TOKEN.value = 1
# warn the user that they cannot run twice
print("Session de " + str(SESSION_LENGTH) + " minutes commençant à " + clock() + ". Ne pas interrompre, ni relancer une deuxième fois.")
if __name__ == '__main__':
multiprocessing.Process(target=dummy_worker).start()
# parameters of the pauses
pause = 5
chrono = 0
nb_sleeps = int(SESSION_LENGTH/pause)
for i in range(nb_sleeps):
time.sleep(pause*60)
chrono = chrono + pause
print('Session ouverte depuis '+str(chrono)+' minutes', end="\r") # perdiodic refreshing
# final message
print("Session de " + str(SESSION_LENGTH) + " minutes terminée à " + clock() + ".")
print("Le serveur s'arrêtera après 10 minutes d'inactivité")
return
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment