Skip to content

Instantly share code, notes, and snippets.

@rgbkrk
Last active August 30, 2018 22:23
Show Gist options
  • Save rgbkrk/1681286cb3313dd5614a11000622600b to your computer and use it in GitHub Desktop.
Save rgbkrk/1681286cb3313dd5614a11000622600b to your computer and use it in GitHub Desktop.
Threading Weirdness with IPython kernels

Background

System:

  • Debian, running on Amazong
  • /root is backed by NFS (Amazon's EFS)

Launch jupyter console --kernel python3 in one terminal, then pstree in another.

In [1]: import threading

In [2]: threading.enumerate()
Out[2]:
[<_MainThread(MainThread, started 140027014350592)>,
 <Thread(Thread-2, started daemon 140026818844416)>,
 <Heartbeat(Thread-3, started daemon 140026738374400)>,
 <ParentPollerUnix(Thread-1, started daemon 140023754278656)>]

In [3]: import os

In [4]: os.getpid()
Out[4]: 6969
root@user-kylek ~# pstree 6969
python3───70*[{python3}]

They definitely seem like zombie threads only 4 shown with the enumerate there. πŸ€·β€β™‚οΈ

root@user-kylek ~# pstree 6969 -ap
python3,6969 -m ipykernel_launcher -f /root/.local/share/jupyter/runtime/kernel-6964.json
  β”œβ”€{python3},6977
  β”œβ”€{python3},6978
  β”œβ”€{python3},6979
  β”œβ”€{python3},6980
  β”œβ”€{python3},6981
  β”œβ”€{python3},6982
  β”œβ”€{python3},6983
  β”œβ”€{python3},6984
  β”œβ”€{python3},6985
  β”œβ”€{python3},6986
  β”œβ”€{python3},6987
  β”œβ”€{python3},6988
  β”œβ”€{python3},6989
  β”œβ”€{python3},6990
  β”œβ”€{python3},6991
  β”œβ”€{python3},6992
  β”œβ”€{python3},6993
  β”œβ”€{python3},6994
  β”œβ”€{python3},6995
  β”œβ”€{python3},6996
  β”œβ”€{python3},6997
  β”œβ”€{python3},6998
  β”œβ”€{python3},6999
  β”œβ”€{python3},7000
  β”œβ”€{python3},7001
  β”œβ”€{python3},7002
  β”œβ”€{python3},7003
  β”œβ”€{python3},7004
  β”œβ”€{python3},7005
  β”œβ”€{python3},7006
  β”œβ”€{python3},7007
  β”œβ”€{python3},7008
  β”œβ”€{python3},7009
  β”œβ”€{python3},7010
  β”œβ”€{python3},7011
  β”œβ”€{python3},7012
  β”œβ”€{python3},7013
  β”œβ”€{python3},7014
  β”œβ”€{python3},7015
  β”œβ”€{python3},7016
  β”œβ”€{python3},7017
  β”œβ”€{python3},7018
  β”œβ”€{python3},7019
  β”œβ”€{python3},7020
  β”œβ”€{python3},7021
  β”œβ”€{python3},7022
  β”œβ”€{python3},7023
  β”œβ”€{python3},7024
  β”œβ”€{python3},7025
  β”œβ”€{python3},7026
  β”œβ”€{python3},7027
  β”œβ”€{python3},7028
  β”œβ”€{python3},7029
  β”œβ”€{python3},7030
  β”œβ”€{python3},7031
  β”œβ”€{python3},7032
  β”œβ”€{python3},7033
  β”œβ”€{python3},7034
  β”œβ”€{python3},7035
  β”œβ”€{python3},7036
  β”œβ”€{python3},7037
  β”œβ”€{python3},7038
  β”œβ”€{python3},7039
  β”œβ”€{python3},7040
  β”œβ”€{python3},7041
  β”œβ”€{python3},7042
  β”œβ”€{python3},7043
  β”œβ”€{python3},7044
  β”œβ”€{python3},7045
  └─{python3},7046

strace kernel

--cap-add SYS_PTRACE

Stick in /usr/local/share/jupyter/kernels/python3-strace/kernel.json:

{
  "argv": [
    "strace",
    "-o",
    "/tmp/straced.txt",
    "/usr/local/bin/python3",
    "-m ipykernel_launcher -f {connection_file}"
   ],
   "display_name": "Python 3 straced",
   "language": "python"
}
@jimcistaro
Copy link

jimcistaro commented Aug 30, 2018

Need to break up the -m/f into args.

{
  "argv": [
    "strace",
    "-o",
    "/tmp/straced.txt",
    "/usr/local/bin/python3",
    "-m", "ipykernel_launcher", "-f", "{connection_file}"
   ],
   "display_name": "Python 3 straced",
   "language": "python"
}

@rgbkrk
Copy link
Author

rgbkrk commented Aug 30, 2018

Thanks, updated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment