Opened 10 years ago

Closed 5 years ago

#1381 closed feature request (fixed)

Add terminateStmt to "GHC as a library"

Reported by: guest Owned by:
Priority: normal Milestone: 7.8.1
Component: GHC API Version: 6.6.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by simonpj)


I would like an extension to the "GHC as a library" API, so that if I have done:

  runStmt someStatement

I can prematurely terminate the execution.

I have posted this request on GHC-users@… and a more thorough explanation can be found there:


Mads Lindstrøm

Change History (10)

comment:1 Changed 10 years ago by simonmar

Milestone: 6.1

comment:2 Changed 9 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:3 Changed 9 years ago by simonmar

Operating System: MultipleUnknown/Multiple

comment:4 Changed 9 years ago by igloo

Milestone: 6.10 branch6.12 branch

comment:5 Changed 7 years ago by igloo

Milestone: 6.12 branch6.12.3

comment:6 Changed 7 years ago by igloo

Milestone: 6.12.3_|_
Priority: lownormal
Type of failure: None/Unknown

comment:7 Changed 5 years ago by edsko

There is currently no good workaround for this, because Panic.interruptTargetThread is not exported, and hence we cannot find the ThreadId of the thread spawned by runStmt. We can avoid runStmt spawning a thread at all by disabling Opt_GhciSandbox so that we can throw UserInterrupt to the thread that calls runStmt, but that means that the debugging facilities don't work anymore.

comment:8 Changed 5 years ago by simonpj

Description: modified (diff)

I'm not familiar with the details, but it sounds as if you are.... any chance of a patch?


comment:9 Changed 5 years ago by marlowsd@…

commit 02c4ab049adeb77b8ee0e3b98fbf0f3026eee453

Author: Simon Marlow <>
Date:   Thu Dec 20 09:18:49 2012 +0000

    Redirect asynchronous exceptions to the sandbox thread in runStmt (#1381)
    See comment for details.
    We no longer use pushInterruptTargetThread/popInterruptTargetThread,
    so these could go away in due course.

 compiler/main/InteractiveEval.hs |   43 ++++++++++++++++++++++++++++---------
 1 files changed, 32 insertions(+), 11 deletions(-)

comment:10 Changed 5 years ago by simonmar

Milestone: _|_7.8.1
Resolution: fixed
Status: newclosed

I believe the above patch fixes this ticket, because you can now just throw an exception to the thread that calls runStmt and the right thing will happen: runStmt will return with RunException e where e is the exception you threw.

Note: See TracTickets for help on using tickets.