End session request

I'm trying to end a session with a POST request:

url = "http://localhost:8080/end_session"
import requests
params = {'session_id':"2019-08-03_20-36-12"} 
r = requests.post(url=url, params=params)
print(r.json())

yet getting a response:

{'ended': False}

Also is there an easy way to get assigned session_id for the live session from jupyter console?

Prodigy version is 1.8.3 and Python version 3.7.3

Thanks

Hi! What exactly are you trying to do? There shouldn't be a need to explicitly end a session and the /end_session endpoint is currently mostly internals for Prodigy Scale and mostly relevant for named multi-user sessions (e.g. if you append something like ?session=foo).

Hi Ines, thanks for fast response. Actually, I'm trying to create a chatbot sort of UI for a client where they can load a .csv file, process it, initiate a session, open prodigy annotation window and kill the server without using terminal window at all.

Ahh, okay! In that case, the end_session endpoint wouldn't work because it really just refers to the internal annotation session rather than the Python session.

If you need to stop the process from Python, you could try something like this and just kill the server on the port you're running Prodigy on:

Alternatively, if you can call into the Jupyter kernels, you could try an approach like the one we're using in our jupyterlab-prodigy extension:

Cool, thanks! I have used this approach described in the first link you have shared:

from psutil import process_iter
from signal import SIGTERM # or SIGKILL

for proc in process_iter():
    for conns in proc.connections(kind='inet'):
        if conns.laddr.port == 8080:
            proc.send_signal(SIGTERM) # or SIGKILL

Just needed to run the .py file with sudo in the first place, then it worked perfectly. I'll check your jupyterlab approach as well, it looks more elegant. Congrats by the way for this amazing extension and please keep up good work.

1 Like