Open justin2004 opened 3 months ago
Hi Justin,
I've been looking into this. The closest thing that I can implement (and I've tested it) is a singleton construction that returns the same reference whenever the constructor is called again. To use your same example, we now have this:
Python 3.11.9 (tags/v3.11.9:de54cf5, Apr 2 2024, 10:12:12) [MSC v.1938 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pysparql_anything as sa
>>> sa.SparqlAnything()
<pysparql_anything.sparql_anything.SparqlAnything object at 0x00000192AE485010>
>>> e = sa.SparqlAnything()
>>> e
<pysparql_anything.sparql_anything.SparqlAnything object at 0x00000192AE485010>
>>> e2 = sa.SparqlAnything("-Xrs", "-Xmx6g")
>>> e2
<pysparql_anything.sparql_anything.SparqlAnything object at 0x00000192AE485010>
>>>
The last example has been added to show that due to limitations with the JNI that first call to the SparqlAnything
constructor is final, as the JVM cannot be shutdown and restarted with new options unless the underlying process is shut down and restarted.
@enridaga, as you gave this a thumbs up wdyt?
thanks @MarcoR1791 , looks good to me. i think as long as there is something like an sa.shutdown()
that last example doesn't bother me since one could shutdown and invoke again with different args.
No probs! Actually finally learnt how Python really creates classes and their instances.
As for the the sa.shutdown()
method, I'm not sure if it can even be done at the moment. See the last comment in issue #6 with links to further related discussions about the JVM and JNI. Obviously if anyone has an idea on the matter I'm very open to hearing about it.
I'm also curious whether there is a specific use case that you have for running PySPARQL in the Python shell rather than using the provided CLI?
As for the the sa.shutdown() method, I'm not sure if it can even be done at the moment.
ah, no worries.
i mostly use the shell to invoke sparql anything. once i did do a deployment using python to invoke sparql anything but i used subprocess.run()
.
i was trying out this project a few weeks ago using python and it was more convenient than subprocess.run()
.
say you are at the REPL and you instantiate the sa engine but you forgot to assign it to a variable....
maybe subsequent invocations should return the same reference?