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