Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

`Kernel._control_lock` created after it may be used

Open Beginner friendly
#1,567 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
backend

Research direction

The issue is in ipykernel/kernelbase.py around line 347 where _control_lock is accessed before being initialized. Look at the __init__ method of the kernel class to see where _control_lock is set. The fix is to ensure the lock is created before any control messages are dispatched. Check the linked branch for the patch as a reference, then verify by running the kernel in a simulated high-latency environment.

Written by the indexing model from the issue text.

Description

I ran into the following exception when running a Notebook inside VSCode with the python environment running on a remote machine (through the VSCode tunnel). The remote machine has a distributed file system which can cause significant latencies when starting a notebook from scratch, which can unearth race conditions that would be unlikely on a normal laptop or desktop machine. I guess our somewhat offbeat use case is the reason this did not get noticed before.

ERROR:tornado.general:Uncaught exception in ZMQStream callback
Traceback (most recent call last):
  File "/apps/gent/RHEL9/cascadelake-ib/software/IPython/9.14.0-GCCcore-15.2.0/lib/python3.14/site-packages/traitlets/traitlets.py", line 651, in get
    value = obj._trait_values[self.name]
            ~~~~~~~~~~~~~~~~~^^^^^^^^^^^
KeyError: '_control_lock'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/apps/gent/RHEL9/cascadelake-ib/software/PyZMQ/27.1.0-GCCcore-15.2.0/lib/python3.14/site-packages/zmq/eventloop/zmqstream.py", line 565, in _log_error
    f.result()
    ~~~~~~~~^^
  File "/apps/gent/RHEL9/cascadelake-ib/software/jupyter-server/2.19.0-GCCcore-15.2.0/lib/python3.14/site-packages/ipykernel/kernelbase.py", line 347, in dispatch_control
    async with self._control_lock:
               ^^^^^^^^^^^^^^^^^^
  File "/apps/gent/RHEL9/cascadelake-ib/software/IPython/9.14.0-GCCcore-15.2.0/lib/python3.14/site-packages/traitlets/traitlets.py", line 706, in __get__
    return self.get(obj, cls)  # type:ignore[return-value]
           ~~~~~~~~^^^^^^^^^^
  File "/apps/gent/RHEL9/cascadelake-ib/software/IPython/9.14.0-GCCcore-15.2.0/lib/python3.14/site-packages/traitlets/traitlets.py", line 668, in get
    value = self._validate(obj, default)
  File "/apps/gent/RHEL9/cascadelake-ib/software/IPython/9.14.0-GCCcore-15.2.0/lib/python3.14/site-packages/traitlets/traitlets.py", line 741, in _validate
    value = self.validate(obj, value)
  File "/apps/gent/RHEL9/cascadelake-ib/software/IPython/9.14.0-GCCcore-15.2.0/lib/python3.14/site-packages/traitlets/traitlets.py", line 2319, in validate
    self.error(obj, value)
    ~~~~~~~~~~^^^^^^^^^^^^
  File "/apps/gent/RHEL9/cascadelake-ib/software/IPython/9.14.0-GCCcore-15.2.0/lib/python3.14/site-packages/traitlets/traitlets.py", line 850, in error
    raise TraitError(e)
traitlets.traitlets.TraitError: The '_control_lock' trait of an IPythonKernel instance expected a Lock, not the NoneType None.

This was with ipykernel v7.2.0 on Redhat Linux 9 (remote machine, HPC infrastructure). I've written a patch for v7.2.0, so we can perform a minimal upgrade of our teaching setup:

https://github.com/tovrstra/ipykernel/tree/bugfix/control_lock_race

I think the same issue (_control_lock created too late) is still present in the main branch. I'll make a PR on the main branch in minute.

Dominant language
Python
Stars
734
Forks
411
Avg merge
1d 2h
Merged PRs (30d)
9

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ipython/ipykernel

All issues in ipython/ipykernel

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.