Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid creating asyncio.Lock at import time #935

Merged
merged 1 commit into from
Jul 29, 2022

Conversation

minrk
Copy link
Contributor

@minrk minrk commented Jul 29, 2022

asyncio.Lock references the current event loop, but there usually isn't one at import time. The result is that importing this handler always instantiates a current loop and attaches a lock to it, which may or may not be the loop that ultimately runs (app.io_loop).

Instead, create lock and attach it to the Handler class upon initializing the first handler of the class, which is always run inside the loop.

Also related to #876

asyncio.Lock references the current event loop.
There usually isn't one at import time.

Instead, create lock and attach it to the Handler class upon initializing the first handler of the class
@minrk minrk added the bug label Jul 29, 2022
for exporter_name in exporters:
try:
async with LOCK:
async with self._exporter_lock:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved acquisition of the lock outside the loop so we aren't acquiring and re-acquiring the same lock for each exporter.

@codecov-commenter
Copy link

Codecov Report

Merging #935 (9b040fe) into main (e32f726) will decrease coverage by 0.05%.
The diff coverage is 83.33%.

@@            Coverage Diff             @@
##             main     #935      +/-   ##
==========================================
- Coverage   72.26%   72.20%   -0.06%     
==========================================
  Files          65       65              
  Lines        7997     8002       +5     
  Branches     1335     1333       -2     
==========================================
- Hits         5779     5778       -1     
- Misses       1811     1814       +3     
- Partials      407      410       +3     
Impacted Files Coverage Δ
jupyter_server/services/nbconvert/handlers.py 87.87% <83.33%> (+2.16%) ⬆️
jupyter_server/services/contents/filemanager.py 70.61% <0.00%> (-0.79%) ⬇️
jupyter_server/serverapp.py 65.48% <0.00%> (-0.19%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e32f726...9b040fe. Read the comment docs.

Copy link
Contributor

@blink1073 blink1073 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@blink1073 blink1073 merged commit f373286 into jupyter-server:main Jul 29, 2022
@blink1073
Copy link
Contributor

@meeseeksdev please backport to 1.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants