# Buggy code
def initialize(self, argv=None):
    """Initialize application, notebooks, writer, and postprocessor"""
    self.init_syspath()
    super().initialize(argv)
    self.init_notebooks()
    self.init_writer()
    self.init_postprocessor()


# Traceback (NotImplementedError)
[NbConvertApp] Converting notebook C:\projects\matplotlib\lib\matplotlib\tests\test_nbagg_01.ipynb to notebook
Traceback (most recent call last):
File "c:\miniconda37-x64\envs\test-environment\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\miniconda37-x64\envs\test-environment\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Miniconda37-x64\envs\test-environment\Scripts\jupyter-nbconvert.EXE\__main__.py", line 7, in <module>
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\jupyter_core\application.py", line 270, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\traitlets\config\application.py", line 837, in launch_instance
app.start()
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\nbconvert\nbconvertapp.py", line 345, in start
self.convert_notebooks()
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\nbconvert\nbconvertapp.py", line 519, in convert_notebooks
self.convert_single_notebook(notebook_filename)
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\nbconvert\nbconvertapp.py", line 484, in convert_single_notebook
output, resources = self.export_single_notebook(notebook_filename, resources, input_buffer=input_buffer)
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\nbconvert\nbconvertapp.py", line 413, in export_single_notebook
output, resources = self.exporter.from_filename(notebook_filename, resources=resources)
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\nbconvert\exporters\exporter.py", line 182, in from_filename
return self.from_file(f, resources=resources, **kw)
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\nbconvert\exporters\exporter.py", line 200, in from_file
return self.from_notebook_node(nbformat.read(file_stream, as_version=4), resources=resources, **kw)
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\nbconvert\exporters\notebook.py", line 32, in from_notebook_node
nb_copy, resources = super().from_notebook_node(nb, resources, **kw)
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\nbconvert\exporters\exporter.py", line 144, in from_notebook_node
nb_copy, resources = self._preprocess(nb_copy, resources)
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\nbconvert\exporters\exporter.py", line 319, in _preprocess
nbc, resc = preprocessor(nbc, resc)
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\nbconvert\preprocessors\base.py", line 47, in __call__
return self.preprocess(nb, resources)
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\nbconvert\preprocessors\execute.py", line 65, in preprocess
self.execute()
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\nbclient\util.py", line 74, in wrapped
return just_run(coro(*args, **kwargs))
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\nbclient\util.py", line 53, in just_run
return loop.run_until_complete(coro)
File "c:\miniconda37-x64\envs\test-environment\lib\asyncio\base_events.py", line 616, in run_until_complete
return future.result()
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\nbclient\client.py", line 519, in async_execute
async with self.async_setup_kernel(**kwargs):
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\async_generator\_util.py", line 34, in __aenter__
return await self._agen.asend(None)
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\nbclient\client.py", line 478, in async_setup_kernel
await self.async_start_new_kernel_client()
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\nbclient\client.py", line 403, in async_start_new_kernel_client
await ensure_async(self.kc.start_channels())
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\jupyter_client\client.py", line 106, in start_channels
self.shell_channel.start()
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\jupyter_client\client.py", line 151, in shell_channel
socket = self.connect_shell(identity=self.session.bsession)
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\jupyter_client\connect.py", line 561, in connect_shell
return self._create_connected_socket('shell', identity=identity)
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\jupyter_client\connect.py", line 545, in _create_connected_socket
sock = self.context.socket(socket_type)
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\zmq\sugar\context.py", line 226, in socket
s = self._socket_class(self, socket_type, **kwargs)
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\zmq\_future.py", line 144, in __init__
self._init_io_state()
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\zmq\asyncio\__init__.py", line 53, in _init_io_state
self.io_loop.add_reader(self._fd, lambda : self._handle_events(0, 0))
File "c:\miniconda37-x64\envs\test-environment\lib\asyncio\events.py", line 501, in add_reader
raise NotImplementedError
NotImplementedError
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\nbclient\client.py", line 360, in _async_cleanup_kernel
await ensure_async(self.kc.stop_channels())
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\jupyter_client\client.py", line 125, in stop_channels
if self.shell_channel.is_alive():
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\jupyter_client\client.py", line 151, in shell_channel
socket = self.connect_shell(identity=self.session.bsession)
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\jupyter_client\connect.py", line 561, in connect_shell
return self._create_connected_socket('shell', identity=identity)
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\jupyter_client\connect.py", line 545, in _create_connected_socket
sock = self.context.socket(socket_type)
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\zmq\sugar\context.py", line 226, in socket
s = self._socket_class(self, socket_type, **kwargs)
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\zmq\_future.py", line 144, in __init__
self._init_io_state()
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\zmq\asyncio\__init__.py", line 53, in _init_io_state
self.io_loop.add_reader(self._fd, lambda : self._handle_events(0, 0))
File "c:\miniconda37-x64\envs\test-environment\lib\asyncio\events.py", line 501, in add_reader
raise NotImplementedError
NotImplementedError
Exception ignored in: <function Socket.__del__ at 0x0000004DEB3CF670>
Traceback (most recent call last):
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\zmq\sugar\socket.py", line 67, in __del__
self.close()
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\zmq\_future.py", line 160, in close
self._clear_io_state()
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\zmq\asyncio\__init__.py", line 60, in _clear_io_state
self.io_loop.remove_reader(self._fd)
File "c:\miniconda37-x64\envs\test-environment\lib\asyncio\events.py", line 504, in remove_reader
raise NotImplementedError
NotImplementedError:
Exception ignored in: <function Socket.__del__ at 0x0000004DEB3CF670>
Traceback (most recent call last):
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\zmq\sugar\socket.py", line 67, in __del__
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\zmq\_future.py", line 160, in close
File "c:\miniconda37-x64\envs\test-environment\lib\site-packages\zmq\asyncio\__init__.py", line 60, in _clear_io_state
File "c:\miniconda37-x64\envs\test-environment\lib\asyncio\events.py", line 504, in remove_reader
NotImplementedError:

# Fixed code
def initialize(self, argv=None):
    """Initialize application, notebooks, writer, and postprocessor"""
    # See https://bugs.python.org/issue37373 :(
    if (
        sys.version_info[0] == 3
        and sys.version_info[1] >= 8
        and sys.platform.startswith("win")
    ):
        asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

    self.init_syspath()
    super().initialize(argv)
    self.init_notebooks()
    self.init_writer()
    self.init_postprocessor()