baztian / jaydebeapi

JayDeBeApi module allows you to connect from Python code to databases using Java JDBC. It provides a Python DB-API v2.0 to that database.
GNU Lesser General Public License v3.0
365 stars 148 forks source link

OSError: JVM is already started #238

Open lilili111a opened 10 months ago

lilili111a commented 10 months ago

When I connect to Phoenix using Python, I intend to initialize a connection in each process. However, I encountered the following issues: User

Traceback (most recent call last): File "/usr/local/python3.9.13/lib/python3.9/multiprocessing/pool.py", line 125, in worker result = (True, func(*args, *kwds)) File "/usr/local/python3.9.13/lib/python3.9/multiprocessing/pool.py", line 51, in starmapstar return list(itertools.starmap(args[0], args[1])) File "/usr/appsoft/iespy/beyond_limit/nopandas.py", line 300, in run_bt bt_instance.run() # ▒▒▒▒▒▒▒▒һ▒▒ run ▒▒▒▒▒ִ▒▒ʵ▒▒▒▒▒Ҫ▒߼▒ File "/usr/appsoft/iespy/beyond_limit/nopandas.py", line 289, in run results = list(executor.map(self.Thread_f, time_slot)) File "/usr/local/python3.9.13/lib/python3.9/concurrent/futures/_base.py", line 609, in result_iterator yield fs.pop().result() File "/usr/local/python3.9.13/lib/python3.9/concurrent/futures/_base.py", line 446, in result return self.get_result() File "/usr/local/python3.9.13/lib/python3.9/concurrent/futures/_base.py", line 391, in get_result raise self._exception File "/usr/local/python3.9.13/lib/python3.9/concurrent/futures/thread.py", line 58, in run result = self.fn(self.args, *self.kwargs) File "/usr/appsoft/iespy/beyond_limit/nopandas.py", line 280, in Thread_f turbine_data = self.get_ls_data(time_slot) File "/usr/appsoft/iespy/beyond_limit/nopandas.py", line 113, in get_ls_data conn = jaydebeapi.connect( File "/usr/local/python3.9.13/lib/python3.9/site-packages/jaydebeapi/init.py", line 412, in connect jconn = _jdbc_connect(jclassname, url, driver_args, jars, libs) File "/usr/local/python3.9.13/lib/python3.9/site-packages/jaydebeapi/init.py", line 198, in _jdbc_connect_jpype jpype.startJVM(jvm_path, args, ignoreUnrecognized=True, File "/usr/local/python3.9.13/lib/python3.9/site-packages/jpype/_core.py", line 166, in startJVM raise OSError('JVM is already started') OSError: JVM is already started """

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/appsoft/iespy/beyond_limit/nopandas.py", line 337, in pool.starmap(run_bt, [(id,parameter_id,start_time, stop_time,normal_power,record_interval,duration,save_path,time_period_and_rate_limit_pair,logger) for id in fjid_czid_subxhid]) File "/usr/local/python3.9.13/lib/python3.9/multiprocessing/pool.py", line 372, in starmap return self._map_async(func, iterable, starmapstar, chunksize).get() File "/usr/local/python3.9.13/lib/python3.9/multiprocessing/pool.py", line 771, in get raise self._value OSError: JVM is already started

I am seeking guidance on addressing the aforementioned challenges. Additionally, are there any recommended approaches to establish multiple connections in order to enhance reading speed? PYTHON

caiwenju commented 2 months ago

你好,你找到问题解决方法了吗?我看根源在于 jpype.isJVMStarted()这个方法判定可能有问题,导致后面的代码jpype.startJVM(jvm_path, *args)又执行了一次,感觉是个bug,判定没启动然后去启动,但是最终却返回已经启动。