Skip to content

Commit

Permalink
Raise exceptions instead of showing
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhozic committed Sep 23, 2023
1 parent 945a785 commit 32c02c5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
5 changes: 5 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ Glossary
Releases
---------------------

v1.1.0
=================
- Instead of showing a coroutine error on screen if it ocurred while running a coroutine with
:func:`~tk_async_execute.utils.async_execute()`, raise the exception instead in :func:`tk_async_execute.async_execute()`.

v1.0.1
=================
- Fix event loop problems on Python before 3.10 due to semaphores (etc.) calling ``get_event_loop`` inside.
Expand Down
2 changes: 1 addition & 1 deletion tk_async_execute/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
VERSION = "1.0.1"
VERSION = "1.1.0"

from .utils import *
from . import widget
7 changes: 7 additions & 0 deletions tk_async_execute/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,16 @@ def async_execute(
-----------
ExecutingAsyncWindow
The progress TopLevel window responsible for ``coro`` execution.
Raises
--------
Exception
Exception that occurred in ``coro`` (if it ocurred). Only raised if ``wait`` is True.
"""
window = ExecutingAsyncWindow(coro, visible, pop_up, callback, master=master)
if wait:
window.wait_window()
if (exc := window.future.exception()) is not None:
raise exc

return window
11 changes: 2 additions & 9 deletions tk_async_execute/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __init__(
sys.stdout = self

self.future = future = asyncio.run_coroutine_threadsafe(coro, self.loop)
future.add_done_callback(lambda fut: self.after_idle(self.destroy, fut))
future.add_done_callback(lambda fut: self.after_idle(self.destroy))

def flush(self):
pass
Expand All @@ -132,14 +132,7 @@ def write(self, text: str):

self.old_stdout.write(text)

def destroy(self, future: asyncio.Future = None) -> None:
if future is not None and (exc := future.exception()) is not None:
messagebox.showerror(
"Coroutine error",
f"{exc}\n(Error while running coroutine: {self.awaitable.__name__})\nType: {exc.__class__}",
master=self
)

def destroy(self) -> None:
sys.stdout = self.old_stdout

if self.callback is not None:
Expand Down

0 comments on commit 32c02c5

Please sign in to comment.