Ouranosinc / PAVICS-e2e-workflow-tests

Test user-level workflow.
Apache License 2.0
0 stars 2 forks source link

Panel export leave zombie firefox processes #107

Closed tlvu closed 1 year ago

tlvu commented 1 year ago

Work-around to shutdown Jupyter env to kill zombie firefox processes.

Could cause process limit exhaustion and maybe memory exhaustion if memory is not freed.

@tlogan2000 Can you add extra info here if needed.

tlogan2000 commented 1 year ago

Here is a way to reproduce the issue in the jupyter hub ... Restarting the kernel and running all cells a few times will build up the number of firefox-esr pids

import psutil
import panel as pn
import numpy as np
import xarray as xr

pn.extension()

def checkIfProcessRunning(processName):
    '''
    Check if there is any running process that contains the given name processName.
    '''
    #Iterate over the all the running process
    for proc in psutil.process_iter():

        # Check if process name contains the given name string.
        if processName.lower() in proc.name().lower():
            return True

    return False;

def findProcessIdByName(processName):
    '''
    Get a list of all the PIDs of a all the running process whose name contains
    the given string processName
    '''
    listOfProcessObjects = []
    #Iterate over the all the running process
    for proc in psutil.process_iter():

       pinfo = proc.as_dict(attrs=['pid', 'name', 'create_time'])
       # Check if process name contains the given name string.
       if processName.lower() in pinfo['name'].lower() :
           listOfProcessObjects.append(pinfo)

    return listOfProcessObjects;

print(checkIfProcessRunning('firefox-esr'))
print(findProcessIdByName('firefox-esr'))

import hvplot.xarray
panel = pn.Column()
data = xr.DataArray(np.random.rand(200,400), name='data')
app = pn.Column(data.hvplot.quadmesh())
app.save('test.html')
for ii in range(0,10):
    data = xr.DataArray(np.random.rand(200,400), name='data')
    app = pn.Column(data.hvplot.quadmesh())
    app.save(f"test{ii}.png")
print(checkIfProcessRunning('firefox-esr'))
print(findProcessIdByName('firefox-esr'))
tlogan2000 commented 1 year ago

Note this is only an issue when exporting to png ... exports to .html do not need to be rendered by the browser I think