Setup schedule_task and multi process server causing OSError(9, 'Bad file descriptor')

Hi, I’m seeing a problem when using schedule_task and --num-procs 2.

I’ve put together this example:

# app.py

import panel as pn
import hvplot.pandas

def plot():
    plot = pn.state.cache['data'].hvplot.line()

    return plot

view = pn.Column(plot)

view.servable()
# setup.py

import panel as pn
import pandas as pd

async def update_cache():
    print('Updating cache...')
    pn.state.cache['data'] = pd.read_csv('assets/data.csv')

# Update data should go here.
pn.state.schedule_task('update', update_cache, cron='0 * * * *')

pn.state.cache['data'] = pd.read_csv('assets/data.csv')
# data.csv

x,y
1,1
2,2
3,3
4,4
5,5
6,6
7,7
8,8

Now when I launch this with
panel serve app.py --setup setup.py --static-dirs assets=./assets

it runs ok, but as soon as I attempt to use a multi process server I get the following:

panel serve app.py --setup setup.py --static-dirs assets=./assets --num-procs 2
2023-02-08 16:24:27,075 Starting Bokeh server version 2.4.3 (running on Tornado 6.2)
2023-02-08 16:24:27,075 User authentication hooks NOT provided (default user enabled)
2023-02-08 16:24:27,079 Cannot start Bokeh server [EBADF]: OSError(9, 'Bad file descriptor')
2023-02-08 16:24:27,079 Cannot start Bokeh server [EBADF]: OSError(9, 'Bad file descriptor')
2023-02-08 16:24:27,229 child 1 (pid 9733) exited with status 1, restarting
2023-02-08 16:24:27,230 child 0 (pid 9732) exited with status 1, restarting

.... repeat a lot and then

2023-02-08 16:24:51,760 child 0 (pid 9933) exited with status 1, restarting
2023-02-08 16:24:51,761 child 1 (pid 9934) exited with status 1, restarting
2023-02-08 16:24:51,763 Cannot start Bokeh server [EBADF]: OSError(9, 'Bad file descriptor')
2023-02-08 16:24:51,763 Cannot start Bokeh server [EBADF]: OSError(9, 'Bad file descriptor')
2023-02-08 16:24:51,902 child 1 (pid 9936) exited with status 1, restarting
ERROR: Too many child restarts, giving up

If I remove the

pn.state.schedule_task('update', update_cache, cron='0 * * * *')

from the setup file then it runs ok.

Am I doing something wrong here or is this unexpected? Thanks!

2 Likes

Hi @DrAstro,
--num-threads instead of --num-procs worked for me
https://panel.holoviz.org/how_to/concurrency/threading.html