# Can't terminate input routine or infinite loops without corrupting Prolog session

**URL:** <https://swi-prolog.discourse.group/t/cant-terminate-input-routine-or-infinite-loops-without-corrupting-prolog-session/6850>\
**Category:** Help!\
**Created:** [September 16, 2023, 5:51pm UTC](https://swi-prolog.discourse.group/t/cant-terminate-input-routine-or-infinite-loops-without-corrupting-prolog-session/6850 "2023-09-16T17:51:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SpiRec](https://avatars.discourse-cdn.com/v4/letter/s/f14d63/32.png) [@SpiRec](https://swi-prolog.discourse.group/u/SpiRec)\
**Post date:** [September 16, 2023, 5:51pm UTC](https://swi-prolog.discourse.group/t/cant-terminate-input-routine-or-infinite-loops-without-corrupting-prolog-session/6850/1 "2023-09-16T17:51:11Z")

</div>

Hello.

I’ve encountered some serious problems with SWI-Prolog 9.0.4-1.x64 under Windows 10 64-bit. Namely with abort after Ctrl + C, e.g. when using read\_line\_to\_string(user\_input, …). SWI-Prolog shows some strange behaviour then (it hangs, with an entering prompt without ?- or anything else, etc.).

When I use repeat(+ fail) and automatically execute it, together with read\_line\_to\_string(user\_input, …) that shall provide the escape conditions, is it normal that SWI-Prolog gets caught in an infinite loop, which I can’t terminate?

When I use read\_line\_to\_string(user\_input, …) without automatic execution and want to terminate it, I can’t without corrupting the Prolog session. When pressing Ctrl + C, then entering b, then entering the same predicate that is problematic, then pressing Ctrl + C again, then entering a and closing the application, I get Windows errors as shown in the attached images.

I’ve installed the latest Visual C++ Redistributable ([https://aka.ms/vs/17/release/vc\_redist.x64.exe](https://aka.ms/vs/17/release/vc_redist.x64.exe)).

![SWI-Prolog_at 'abort'_1](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/2X/6/6025fb579f52fc8de96766284ad5a28ff0dc2ae1.jpeg)  
 ![SWI-Prolog_at 'abort'_2](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/2X/1/1f134b0bc2f12b935506a96eb90679de1e091e1b.jpeg)

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [September 16, 2023, 6:03pm UTC](https://swi-prolog.discourse.group/t/cant-terminate-input-routine-or-infinite-loops-without-corrupting-prolog-session/6850/2 "2023-09-16T18:03:11Z")

</div>

This seems related (on Linux): [ctrl-C in read leads exit from REPL · Issue #1097 · SWI-Prolog/swipl-devel · GitHub](https://github.com/SWI-Prolog/swipl-devel/issues/1097)

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [September 17, 2023, 2:45pm UTC](https://swi-prolog.discourse.group/t/cant-terminate-input-routine-or-infinite-loops-without-corrupting-prolog-session/6850/3 "2023-09-17T14:45:16Z")

</div>

> [@peter.ludemann](#):
>
> This seems related (on Linux):

Thanks for reminding on this dangling issue. That looks fixed with 9728ba8a7cc83ae3a02b71fd7684063ee0ffbff3. For me (with the above patch that could be related, but I’m not sure), swipl-win.exe (the windowed version) works almost fine for the OP’s problem. The only thing is that it does not re-prompt after an abort, but hitting RETURN it does.

> [@SpiRec](#):
>
> is it normal that [SWI-Prolog](https://www.swi-prolog.org/pldoc/doc_for?object=manual) gets caught in an infinite loop, which I can’t terminate?

Should not be normal, but completely ruling it out is also hard. Interrupts are handled synchronously and there is code that doesn’t check for interrupts for too long. On non-Windows a second Ctrl-C invokes an unsafe synchronous interrupt.

Toplevel reading and interrupts have lots of different scenarios depending on OS, type of embedding and command line editor used.
