django 使用jpype 报错:raise+OSError('JVM+cannot+be+restarted')
#调用jar包 def getJar(arg1,arg2): jarpath = os.path.join(os.path.abspath('.'), 'tools/GetTest-1.0-SNAPSHOT.jar') print(jarpath) if not jpype.isJVMStarted(): print('--------startjvm---------') jpype.startJVM(jpype.getDefaultJVMPath(), "-ea", "-Djava.class.path=%s" % jarpath) if not jpype.isThreadAttachedToJVM(): print('-----attaching jvm-----') jpype.attachThreadToJVM() Client = jpype.JClass('cn.test.Client') #调用jar包非静态方法 t = Client() result = t.getPhoneSecretKey(arg1, arg2) time.sleep(1)
#jpype.shutdownJVM() 一定要注释掉!!!!!! return result def inter(request): if request.method == "POST": try: result = getJar(arg1, arg2) except Exception as e: print('traceback.print_exc():' + traceback.print_exc()) return JsonResponse({'result':'500'}) return JsonResponse(result)