Skip to content

Conversation

philippjfr
Copy link
Contributor

@philippjfr philippjfr commented Nov 17, 2022

The _change_callbacks dictionary is being iterated over directly which means that when another thread removes or adds a callback we get RuntimeError: dictionary changed size during iteration.

Due to the nature of threading issues I don't have a good reproducer.

@codecov
Copy link

codecov bot commented Nov 17, 2022

Codecov Report

Merging #12623 (14eaa5c) into branch-3.1 (4aea477) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           branch-3.1   #12623   +/-   ##
===========================================
  Coverage       92.16%   92.17%           
===========================================
  Files             313      313           
  Lines           19591    19595    +4     
===========================================
+ Hits            18057    18061    +4     
  Misses           1534     1534           

@mattpap mattpap added this to the 3.1 milestone Nov 21, 2022
The `_change_callbacks` dictionary is being iterated over directly which means that when another thread removes or adds a callback we get `RuntimeError: dictionary changed size during iteration`.

This PR simply makes a copy of the dictionary so we can iterate over it safely.
@bryevdv bryevdv force-pushed the change-callback-threadsafe branch from 2b59905 to df2ee9a Compare December 6, 2022 22:53
@bryevdv
Copy link
Member

bryevdv commented Dec 6, 2022

cc @philippjfr apologies for the rebase, some recent linter fixes needed to be brought in. Please take a look when you can, I'd like to include this in 3.0.3

I added tests for the new methods, but not that the trigger_ methods call them. In fact there are already TODOs for those two:

    # TODO (bev) def test_trigger_event
    # TODO (bev) def test_trigger_on_change

so this just preserves the status quo at least.

@bryevdv bryevdv force-pushed the change-callback-threadsafe branch from 768b7e1 to 47f0d6a Compare December 6, 2022 23:30
@bryevdv bryevdv force-pushed the change-callback-threadsafe branch from 47f0d6a to 14eaa5c Compare December 6, 2022 23:33
@bryevdv
Copy link
Member

bryevdv commented Dec 7, 2022

OK manual testing seems to be good, I am going to go ahead and merge to get into the backports PR. @philippjfr lmk if you have any concerns

@bryevdv bryevdv merged commit 17cc3af into branch-3.1 Dec 7, 2022
@bryevdv bryevdv deleted the change-callback-threadsafe branch December 7, 2022 00:25
@bryevdv bryevdv mentioned this pull request Dec 7, 2022
bryevdv added a commit that referenced this pull request Dec 7, 2022
* Ensure change callback manipulation is threadsafe

The `_change_callbacks` dictionary is being iterated over directly which means that when another thread removes or adds a callback we get `RuntimeError: dictionary changed size during iteration`.

This PR simply makes a copy of the dictionary so we can iterate over it safely.

* Also handle event callbacks

* factor callback lookup into methods returning tuples

Co-authored-by: Bryan Van de Ven <bryan@bokeh.org>
@bryevdv bryevdv modified the milestones: 3.1, 3.0.3 Dec 7, 2022
@bryevdv bryevdv added type: bug python Issues that should only require updating Python code reso: completed and removed reso: completed type: bug labels Dec 7, 2022
@philippjfr
Copy link
Contributor Author

Thanks and sorry I didn't get around to add a test.

Chiemezuo pushed a commit to Chiemezuo/bokeh that referenced this pull request Aug 27, 2024
* Ensure change callback manipulation is threadsafe

The `_change_callbacks` dictionary is being iterated over directly which means that when another thread removes or adds a callback we get `RuntimeError: dictionary changed size during iteration`.

This PR simply makes a copy of the dictionary so we can iterate over it safely.

* Also handle event callbacks

* factor callback lookup into methods returning tuples

Co-authored-by: Bryan Van de Ven <bryan@bokeh.org>
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
python Issues that should only require updating Python code reso: completed status: accepted type: bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants