# What underlying feature supports the pengine\_input predicate?

**URL:** <https://swi-prolog.discourse.group/t/what-underlying-feature-supports-the-pengine-input-predicate/722>\
**Category:** Help!\
**Created:** [May 24, 2019, 8:07pm UTC](https://swi-prolog.discourse.group/t/what-underlying-feature-supports-the-pengine-input-predicate/722 "2019-05-24T20:07:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![prodog](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@prodog](https://swi-prolog.discourse.group/u/prodog)\
**Post date:** [May 24, 2019, 8:07pm UTC](https://swi-prolog.discourse.group/t/what-underlying-feature-supports-the-pengine-input-predicate/722/1 "2019-05-24T20:07:59Z")

</div>

I’m using: SWI-Prolog version 8.0.2 on Ubuntu Linux 18.04.

I am really pleased with the `pengine_input` feature in Pengines. It’s opens up a whole legion of interesting app possibilities. I am curious as to what underlying SWI-Prolog (i.e. - library, predicate, package, etc.) allows the SWI-Prolog engine to halt execution in the middle of a query being executed, and perform an asynchronous and apparently blocking wait for input? That’s a truly impressive feature!

Also, is it possible to freeze the complete execution state of an SWI-Prolog interpreter in the middle of a query execution, persist it to storage, and then restore it from storage later with it ending up in the same state as when it was stored/saved? Something akin to a Python pickle/unpickle operation?

---

<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:** [May 25, 2019, 7:34am UTC](https://swi-prolog.discourse.group/t/what-underlying-feature-supports-the-pengine-input-predicate/722/2 "2019-05-25T07:34:28Z")

</div>

> [@prodog](#):
>
> allows the SWI-Prolog engine to halt execution in the middle of a query being executed, and perform an asynchronous and apparently blocking wait for input?

Why is this so hard? It isn’t much different from _read_. You tell the client you want input and then you wait on a message queue until the client delivers the input.

> [@prodog](#):
>
> persist it to storage, and then restore it from storage

With some limitations that would be quite feasible. Using qsave\_program/2 you can already save the program. Saving an engine shouldn’t be too hard as the state is well isolated. Not sure how useful it is though.

---

<div class="post-metadata">

**Author:** ![prodog](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@prodog](https://swi-prolog.discourse.group/u/prodog)\
**Post date:** [May 25, 2019, 12:17pm UTC](https://swi-prolog.discourse.group/t/what-underlying-feature-supports-the-pengine-input-predicate/722/3 "2019-05-25T12:17:26Z")

</div>

Perfect, thanks!:

[http://www.swi-prolog.org/pldoc/doc\_for?object=qsave\_program/2](http://www.swi-prolog.org/pldoc/doc_for?object=qsave_program/2)

---

<div class="post-metadata">

**Author:** ![prodog](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@prodog](https://swi-prolog.discourse.group/u/prodog)\
**Post date:** [May 26, 2019, 6:36pm UTC](https://swi-prolog.discourse.group/t/what-underlying-feature-supports-the-pengine-input-predicate/722/4 "2019-05-26T18:36:03Z")

</div>

@jan - what is the complement function to **qsave\_program** that loads a saved program? I’ve surveyed the docs and I don’t see anything like a function named **qload\_program**.
