yuce / pyswip

PySwip is a Python - SWI-Prolog bridge enabling to query SWI-Prolog in your Python programs. It features an (incomplete) SWI-Prolog foreign language interface, a utility class that makes it easy querying with Prolog and also a Pythonic interface.
MIT License
464 stars 97 forks source link

Redefined static procedure after clearing Prolog() object #156

Open deRemo opened 9 months ago

deRemo commented 9 months ago

I'm using pyswip in a python script very similar to this one:

for path in plpaths:
    prolog = Prolog()
    prolog.consult(path)

    prolog.query(...)
[...]

The consulted files include a 'global' pl file shared by everyone. I'm encountering this problem when len(plpaths) > 1:

Warning: /path/to/included/file.pl:5:
Warning:    Redefined static procedure pred/3
Warning:    Previously defined at /path/to/included/file.pl:5
[...]

I tried cleaning up the prolog variable (prolog = None and del prolog), but didn't work. I tried re-importing the module at each iteration, but nothing. Is there a fix for this?

femartip commented 6 months ago

Had the same problem. It seems that the Prolog() object is a singleton and so it is created in the module level. However I have seen that pywip_notebook creates a wrapper around the Prolog class so it creates the Prolog instance in its own module. I am trying with this.