ipykernel: AttributeError: 'NoneType' object has no attribute 'thread'

After running a jupyter notebook using jupyter nbconvert --to notebook --execute <notebook_name> --ExecutePreprocessor.timeout=15000 --inplace, I get the following error:

Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/usr/lib/python3.5/logging/__init__.py", line 1881, in shutdown
    h.flush()
  File "/home/kbuilder/.local/lib/python3.5/site-packages/absl/logging/__init__.py", line 882, in flush
    self._current_handler.flush()
  File "/home/kbuilder/.local/lib/python3.5/site-packages/absl/logging/__init__.py", line 776, in flush
    self.stream.flush()
  File "/tmpfs/src/tf_docs_env/lib/python3.5/site-packages/ipykernel/iostream.py", line 341, in flush
    if self.pub_thread.thread.is_alive():
AttributeError: 'NoneType' object has no attribute 'thread'

This is the line where it fails: https://github.com/ipython/ipykernel/blob/master/ipykernel/iostream.py#L341

What can I do to fix it?

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 18
  • Comments: 23 (1 by maintainers)

Commits related to this issue

Most upvoted comments

kaggle notebook error …

Hi, I used to have this issue as well:

jupyter              1.0.0
jupyter-client       5.3.1
jupyter-console      6.0.0
jupyter-core         4.5.0
jupyterlab           1.1.1
jupyterlab-server    1.0.6
ipykernel            5.1.1
ipython              7.8.0
ipython-genutils     0.2.0
ipywidgets           7.5.1

Downgrading ipykernel to 5.1.1 fixed it.

same error when running kernel on kaggle

Time
#
Log Message
1.53
1
[NbConvertApp] Converting notebook __notebook__.ipynb to notebook
3.62
2
[NbConvertApp] Executing notebook with kernel: python3
4.01
3
2019-08-23 21:02:23.719627: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudart.so.10.0
6.54
4
2019-08-23 21:02:26.249148: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2200000000 Hz
6.54
5
2019-08-23 21:02:26.249541: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x55c9e57fd190 executing computations on platform Host. Devices: 2019-08-23 21:02:26.249701: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): <undefined>, <undefined>
6.55
6
2019-08-23 21:02:26.256911: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcuda.so.1
6.67
7
2019-08-23 21:02:26.381657: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
6.68
8
2019-08-23 21:02:26.384756: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x55c9e58b94e0 executing computations on platform CUDA. Devices: 2019-08-23 21:02:26.384791: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): Tesla P100-PCIE-16GB, Compute Capability 6.0 2019-08-23 21:02:26.385175: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
6.68
9
2019-08-23 21:02:26.385969: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties: name: Tesla P100-PCIE-16GB major: 6 minor: 0 memoryClockRate(GHz): 1.3285 pciBusID: 0000:00:04.0 2019-08-23 21:02:26.386051: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudart.so.10.0
6.68
10
2019-08-23 21:02:26.390300: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcublas.so.10.0
6.69
11
2019-08-23 21:02:26.392756: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcufft.so.10.0 2019-08-23 21:02:26.393349: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcurand.so.10.0
6.69
12
2019-08-23 21:02:26.396490: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcusolver.so.10.0 2019-08-23 21:02:26.398342: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcusparse.so.10.0
6.70
13
2019-08-23 21:02:26.404279: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudnn.so.7 2019-08-23 21:02:26.404435: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
6.70
14
2019-08-23 21:02:26.405313: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2019-08-23 21:02:26.406100: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0 2019-08-23 21:02:26.406173: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcudart.so.10.0
7.23
15
2019-08-23 21:02:26.941824: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1181] Device interconnect StreamExecutor with strength 1 edge matrix: 2019-08-23 21:02:26.941888: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1187] 0 2019-08-23 21:02:26.941901: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1200] 0: N 2019-08-23 21:02:26.942225: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
7.24
16
2019-08-23 21:02:26.943237: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2019-08-23 21:02:26.944098: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1326] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 9768 MB memory) -> physical GPU (device: 0, name: Tesla P100-PCIE-16GB, pci bus id: 0000:00:04.0, compute capability: 6.0)
10.06
17
Error in atexit._run_exitfuncs: Traceback (most recent call last): File "/opt/conda/lib/python3.6/logging/__init__.py", line 1944, in shutdown h.flush() File "/opt/conda/lib/python3.6/site-packages/absl/logging/__init__.py", line 882, in flush self._current_handler.flush() File "/opt/conda/lib/python3.6/site-packages/absl/logging/__init__.py", line 776, in flush self.stream.flush() File "/opt/conda/lib/python3.6/site-packages/ipykernel/iostream.py", line 341, in flush if self.pub_thread.thread.is_alive(): AttributeError: 'NoneType' object has no attribute 'thread'
10.69
18
[NbConvertApp] Writing 24406 bytes to __notebook__.ipynb
11.56
19
[NbConvertApp] Converting notebook __notebook__.ipynb to html
11.97
20
[NbConvertApp] Writing 325062 bytes to __results__.html `

I think this is already fixed in v6.13.0 (thanks to PR #899). Can anyone confirm?

I confirm also seeing the problem with ipykernel 5.3.4. Seemingly it returned 😦

I have a similar issue when running,

jupyter nbconvert --to html --execute notebooks.ipynb

on the following notebook:

from tqdm.notebook import tqdm
from time import sleep

pbar = tqdm(total=10)

for i in range(5):
    sleep(1)
    pbar.update(1)

pbar.close()

Running the notebook from jupyter notebook does not produce an error. However, with nbconvert I get,

[NbConvertApp] Converting notebook notebooks.ipynb to html
[NbConvertApp] Executing notebook with kernel: python3
Exception ignored in: <function tqdm.__del__ at 0x7f9156085af0>
Traceback (most recent call last):
  File "/Users/user1/anaconda3/envs/book/lib/python3.8/site-packages/tqdm/std.py", line 1124, in __del__
    self.close()
  File "/Users/user1/anaconda3/envs/book/lib/python3.8/site-packages/tqdm/notebook.py", line 271, in close
    self.sp(bar_style='danger')
  File "/Users/user1/anaconda3/envs/book/lib/python3.8/site-packages/tqdm/notebook.py", line 170, in display
    rtext.value = right
  File "/Users/user1/anaconda3/envs/book/lib/python3.8/site-packages/traitlets/traitlets.py", line 585, in __set__
    self.set(obj, value)
  File "/Users/user1/anaconda3/envs/book/lib/python3.8/site-packages/traitlets/traitlets.py", line 574, in set
    obj._notify_trait(self.name, old_value, new_value)
  File "/Users/user1/anaconda3/envs/book/lib/python3.8/site-packages/traitlets/traitlets.py", line 1134, in _notify_trait
    self.notify_change(Bunch(
  File "/Users/user1/anaconda3/envs/book/lib/python3.8/site-packages/ipywidgets/widgets/widget.py", line 605, in notify_change
    self.send_state(key=name)
  File "/Users/user1/anaconda3/envs/book/lib/python3.8/site-packages/ipywidgets/widgets/widget.py", line 489, in send_state
    self._send(msg, buffers=buffers)
  File "/Users/user1/anaconda3/envs/book/lib/python3.8/site-packages/ipywidgets/widgets/widget.py", line 737, in _send
    self.comm.send(data=msg, buffers=buffers)
  File "/Users/user1/anaconda3/envs/book/lib/python3.8/site-packages/ipykernel/comm/comm.py", line 122, in send
    self._publish_msg('comm_msg',
  File "/Users/user1/anaconda3/envs/book/lib/python3.8/site-packages/ipykernel/comm/comm.py", line 66, in _publish_msg
    self.kernel.session.send(self.kernel.iopub_socket, msg_type,
  File "/Users/user1/anaconda3/envs/book/lib/python3.8/site-packages/jupyter_client/session.py", line 758, in send
    stream.send_multipart(to_send, copy=copy)
  File "/Users/user1/anaconda3/envs/book/lib/python3.8/site-packages/ipykernel/iostream.py", line 264, in send_multipart
    return self.io_thread.send_multipart(*args, **kwargs)
  File "/Users/user1/anaconda3/envs/book/lib/python3.8/site-packages/ipykernel/iostream.py", line 214, in send_multipart
    self.schedule(lambda : self._really_send(*args, **kwargs))
  File "/Users/user1/anaconda3/envs/book/lib/python3.8/site-packages/ipykernel/iostream.py", line 207, in schedule
    f()
  File "/Users/user1/anaconda3/envs/book/lib/python3.8/site-packages/ipykernel/iostream.py", line 214, in <lambda>
    self.schedule(lambda : self._really_send(*args, **kwargs))
  File "/Users/user1/anaconda3/envs/book/lib/python3.8/site-packages/ipykernel/iostream.py", line 222, in _really_send
    self.socket.send_multipart(msg, *args, **kwargs)
AttributeError: 'NoneType' object has no attribute 'send_multipart'
[NbConvertApp] Writing 283717 bytes to notebooks.html
jupyter                   1.0.0                    py38_7  
jupyter_client            6.1.6                      py_0  
jupyter_console           6.2.0                      py_0  
jupyter_core              4.6.3                    py38_0  
ipykernel                 5.3.4            py38h5ca1d4c_0  
ipython                   7.18.1           py38h5ca1d4c_0  
ipython_genutils          0.2.0                    py38_0  
ipywidgets                7.5.1                      py_1  
scipy                     1.5.0            py38hbab996c_0  

I have initially raised the issue here: https://github.com/tqdm/tqdm/issues/1092