Guest User

Untitled

a guest
Feb 19th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. import subprocess
  2. import py4j.java_gateway import JavaGateway
  3.  
  4. def start_java():
  5. # Note: I assume that my_library.jar contains the library you want to expose with your CLI program.
  6. ARGS = ['java', '-cp', '/path/to/my_library.jar:/path/to/my/class_dir:/path/to/py4j-java.jar', 'p1.MyApplication']
  7. p = subprocess.Popen(ARGS)
  8. print('Java Started: {0}'.format(p.pid))
  9.  
  10. def stop_java():
  11. gateway = JavaGateway()
  12. gateway.shutdown()
  13. # Two alternatives:
  14. # (1) You could call a method on the Java side that calls System.exit(0);
  15. # (2) You could save the pid from start_java and kill the process, but you need to handle mac, linux, and
  16. # windows...
Add Comment
Please, Sign In to add comment