Re: Problem using ontology in multi-process environment
Posted by Jiba on
URL: http://owlready.306.s1.nabble.com/Problem-using-ontology-in-multi-process-environment-tp3198p3230.html
Hi,
The problem is that the quadstore is stored in a SQLite3 database, by default in memory. When processes are created, each has a copy of the database. Thus, modifying one copy does not alter the other.
In order to share the quadstore between several processes, you need to put the quadstore in a database on disk, to activate flag allowing the database to be shared, and to save the quadstore (=commit the database) after each modification.
This can be done by adding the following just after "if __name__ == '__main__': " :
default_world.set_backend(filename = "/tmp/quadstore.sqlite3", exclusive = False)
(NB you may adapt the filename of the SQLite3 database as you want)
And then, after creating the new class, you need to save the quadstore as follows:
with ontology:
NewClass = types.new_class(new_class_name, (Thing,))
default_world.save()
With these changes, your example works as expected on my computer.
Jiba