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

Do not join refresh thread for Live under lock #928

Closed

Conversation

cjolowicz
Copy link

@cjolowicz cjolowicz commented Jan 14, 2021

In the Live.stop() method, release self._lock before joining the refresh thread. Re-acquire the lock when Thread.join returns or raises an exception.

This fixes the following deadlock:

  1. Live.stop: The main thread acquires the lock.
  2. _RefreshThread.run: The refresh thread waits for the lock.
  3. Live.stop: The main thread stops and joins the refresh thread.

Deadlock occurs because the main thread waits for the refresh thread to exit, while the refresh thread waits for the main thread to release the lock.

Fixes #927

In the Live.stop() method, release self._lock before joining the refresh thread.
Re-acquire the lock when Thread.join returns or raises an exception.

This fixes the following deadlock:

1. (Live.stop): The main thread acquires the lock.
2. (_RefreshThread.run) The refresh thread waits for the lock.
3. (Live.stop) The main thread stops and joins the refresh thread.

Deadlock occurs because the main thread waits for the refresh thread to exit,
while the refresh thread waits for the main thread to release the lock.
@codecov
Copy link

codecov bot commented Jan 14, 2021

Codecov Report

Merging #928 (73fae54) into master (f7c0783) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #928   +/-   ##
=======================================
  Coverage   99.54%   99.54%           
=======================================
  Files          58       58           
  Lines        5065     5068    +3     
=======================================
+ Hits         5042     5045    +3     
  Misses         23       23           
Flag Coverage Δ
unittests 99.54% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
rich/live.py 100.00% <100.00%> (ø)
rich/syntax.py 100.00% <100.00%> (ø)

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 aca0b60...73fae54. Read the comment docs.

@willmcgugan
Copy link
Collaborator

Closing if favor of #930

@cjolowicz cjolowicz closed this Jan 15, 2021
@cjolowicz cjolowicz deleted the fix-deadlock-status-exit branch January 15, 2021 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Deadlock when exiting Status context
2 participants