jupyterhub / the-littlest-jupyterhub

Simple JupyterHub distribution for 1-100 users on a single server
https://tljh.jupyter.org
BSD 3-Clause "New" or "Revised" License
1.04k stars 340 forks source link

Set timeout for some subprocess calls #228

Open tkang007 opened 6 years ago

tkang007 commented 6 years ago

Hi,

How about adding timeout parameter when using subprocess methodss: check_output, check_run, check_call,... to avoid block forever at certain cases?

Especially, network related command could be block at various reason, such as proxy down,...

I think timeout value could be 10 times of usual elapsed time.

In my case, it was blocked until interrupting as below stack.

File "/opt/tljh/hub/lib/python3.6/site-packages/tljh/installer.py", line 113, in ensure_chp_package ], cwd=prefix, stderr=subprocess.STDOUT) File "/usr/lib/python3.6/subprocess.py", line 336, in check_output **kwargs).stdout File "/usr/lib/python3.6/subprocess.py", line 405, in run stdout, stderr = process.communicate(input, timeout=timeout) File "/usr/lib/python3.6/subprocess.py", line 830, in communicate stdout = self.stdout.read()

choldgraf commented 6 years ago

Hey there - thanks for the suggestion! One challenge I can think of here is that it's hard to know what's the right amount of time to choose for everything. Maybe this would be better exposed as a configuration variable somewhere?