Comments (9)
You can pass maxresult=1
to retrieve only a single answer, like:
solu = prolog.query("get_list(3, X)", maxresult=1)
from pyswip.
But this does not help solve the segfault though. It seems the segfault occurs at some clean up stage:
from pyswip import *
prolog = Prolog()
prolog.consult("test_list.pl")
solu = prolog.query("get_list(3, X)", maxresult=1)
for s in solu:
print(s)
break
print(s['X'][1])
print("prog end")
The corresponding output is:
{'X': [3, 2, 1]}
2
prog end
fish: 'python spec_verify.py' terminated by signal SIGSEGV (Address boundary error)
If I change to bash:
{'X': [3, 2, 1]}
2
prog end
Segmentation fault: 11
from pyswip.
Can you remove the break
in the loop and try again?
from pyswip.
The program either stuck or quit unexpectedly. The terminal window closed itself when the program quits.
from pyswip.
This is the code I've tried:
from pyswip import Prolog
prolog = Prolog()
prolog.consult("test_list.pl")
solu = prolog.query("get_list(3, X)", maxresult=1)
for i in solu:
print (i)
This is what I get when running it:
$ python test_list.py
{'X': [3, 2, 1]}
$
No segfaults, etc. (of course that doesn't rule out a bug in PySwip). This is on Ubuntu 18.04, Python 3.6.8, SWI 7.6.4. All of those using Ubuntu's packages.
Did you try your code using SWI-Prolog? It doesn't terminate after the first solution.
from pyswip.
Yes, I have tried it with the SWI-Prolog and it worked normally. I think I can try to install the packages again on Ubuntu system and see whether the problem is MacOSX specific. :)
from pyswip.
This is what I've tried with SWI-Prolog:
?- [test_list].
true.
?- get_list(3, X).
X = [3, 2, 1] ; <-- doesn't terminate after that
What do you get after [3, 2, 1]
?
from pyswip.
Hi there,
I can confirm that there is definitely some problem here. I encountered a similar situation with a segv on both Windows and MacOSX, with SWI-PL 7.6 and 8.0. I get this result on the test case:
$ python test_list.py
{'X': [3, 2, 1]}
Exception ignored in: <generator object Prolog._QueryWrapper.__call__ at 0x0000019B3385F580>
Traceback (most recent call last):
File "C:\Local\PyConfig\envs\aienv\lib\site-packages\pyswip\prolog.py", line 130, in __call__
OSError: exception: access violation reading 0x0000000000000110
It seems that an exception occurs inside the finally clause of the call to Prolog, precisely in the call to PL_cut_query(swipl_qid)
.
I tried to replace this call with PL_close_query(swipl_qid)
but the result is the same.
Any idea of what can cause that ?
Regards,
from pyswip.
More on this issue. I get a constant segfault if I run the query this way:
q = prolog.query("get_list(3, X)", maxresult=1)
solu = next(q)
print(solu['X'])
but everything is perfect if I run it this way:
solu = next(prolog.query("get_list(3, X)", maxresult=1))
print(solu['X'])
The difference is about when the finally
clause is called. In the later case, the finally
clause is called before printing the term, whereas it is called after printing it int the former case.
And actually the reason lies in a not so well known behavior of Python generators:
https://stackoverflow.com/questions/56062909/try-finally-in-python-3-generator
from pyswip.
Related Issues (20)
- Errors on queries
- Powered by PySwip HOT 2
- Swipl DCG does not appear to function HOT 1
- Problem running the quick test code on Windows 11 HOT 2
- Compatibility with Mac M1 chip HOT 6
- How to clean prolog ?
- Error with SWI-Prolog v8.5.3 and pyswipl 0.2.10
- Error by using char '¬' as operator in prolog and translate it with pyswip
- pyswip cannot work with flask HOT 1
- Operating with dictionaries in pyswip
- Please provide support for M1 Macs HOT 2
- Core dump HOT 9
- pyswip incompatible with swi-prolog 9.0.0? HOT 6
- Could not find the SWI-Prolog library in this platform. HOT 3
- efficient way of adding and removing facts
- How do I use prolog's debug/trace mode in python HOT 1
- Reviewers
- Redefined static procedure after clearing Prolog() object HOT 1
- Problem in representing incomplete structures
- Powered by Pyswip HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyswip.