Skip to content

Commit

Permalink
Fix out-of-order cancellation (#450)
Browse files Browse the repository at this point in the history
* Fix out-of-order cancellation

* Add changelog entry
  • Loading branch information
mdickinson committed Jul 26, 2021
1 parent 86ba569 commit 32b9a92
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/source/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ Documentation
* The ``pi_iterations`` example has been fixed to give correct counts.
Previously it was giving incorrect results as a result of NumPy integer
overflow.
* The ``prime_counting`` example has been fixed to avoid an occasional
``AttributeError`` under unusual timing conditions.


Release 0.2.0
Expand Down
8 changes: 4 additions & 4 deletions docs/source/guide/examples/prime_counting.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ def cancel(self):
"""
Cancel the running future when the cancel button is pressed.
"""
self.future.cancel()
self._cancel_button.setEnabled(False)
self.message = "Cancelling\N{HORIZONTAL ELLIPSIS}"
cancelled = self.future.cancel()
if cancelled:
self.message = "Cancelling\N{HORIZONTAL ELLIPSIS}"

# Private traits ##########################################################

Expand All @@ -83,7 +84,7 @@ def _create_cancel_button(self, parent):
"Cancel", QtGui.QDialogButtonBox.RejectRole
)
self._cancel_button.setDefault(True)
buttons.rejected.connect(self.cancel)
buttons.rejected.connect(self.cancel, type=QtCore.Qt.QueuedConnection)
return buttons

def _create_message(self, dialog, layout):
Expand Down Expand Up @@ -127,7 +128,6 @@ def _report_progress(self, event):

@observe("future:done")
def _respond_to_completion(self, event):
self.future = None
self.close()


Expand Down

0 comments on commit 32b9a92

Please sign in to comment.