Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def sxstart():
from py4j.java_gateway import JavaGateway
try:
JavaGW = JavaGateway()
SXPKG = JavaGW.jvm.org.sikuli
return (JavaGW, SXPKG)
except:
print("sxstart: SikuliX not running")
exit(1)
def __init__(self):
self.gateway = JavaGateway()
self.analyzer = self.gateway.entry_point
self.pos_tags = self._pos_tags()
self.feat_tags = self._feat_tags()
self.chunk_tags = self._chunk_tags()
self.synchunk_tags = self._synchunk_tags()
def __init__(self, driver_name, url, username, password, impersonation_property=None, impersonation_user=None):
if 'py4j' not in sys.modules:
raise Exception('Required py4j module is not imported.')
os.environ["PATH"] = os.environ["PATH"] + ':/usr/java/default/bin' # TODO: more generic
classpath = os.environ.get('CLASSPATH', '')
if DBPROXY_EXTRA_CLASSPATH.get():
classpath = '%s:%s' % (DBPROXY_EXTRA_CLASSPATH.get(), classpath)
self.gateway = JavaGateway.launch_gateway(classpath=classpath)
self.jdbc_driver = driver_name
self.db_url = url
self.username = username
self.password = password
if impersonation_property and impersonation_user:
self.db_url += ";{}={};".format(impersonation_property, impersonation_user)
self.conn = None
def __init__(self, index_path):
"""
Constructor for the Pyserini class.
Parameters
----------
index_path : str
The directory path for the Lucene index.
"""
self.gateway = JavaGateway()
self.index = self.gateway.jvm.java.lang.String(index_path)
self.pyserini = self.gateway.jvm.io.anserini.py4j.PyseriniEntryPoint()
self.pyserini.initializeWithIndex(index_path)
def _setup_py4j_client_connection(self):
gateway_params = GatewayParameters(port=self._java_port,
auto_field=True,
auto_close=True,
eager_load=True)
callback_server_params = CallbackServerParameters(port=0,
daemonize=True,
daemonize_connections=True,
eager_load=True)
self._gateway = JavaGateway(gateway_parameters=gateway_params,
callback_server_parameters=callback_server_params,
python_server_entry_point=self)
self._component_via_py4j = self._gateway.entry_point.getComponent()
if not self._component_via_py4j:
raise MLCompException("None reference of py4j java object!")
if self._verbose:
self._logger.debug(self._prefix_msg + "Py4J component referenced successfully! comp_via_py4j: {}"
.format(self._component_via_py4j))
self._component_via_py4j.setEnvAttributes(self.get_wid(), self._verbose)
def _start_gateway(self):
# auto select callback server port and reset it in java env
self.gateway = JavaGateway(gateway_parameters=GatewayParameters(
port=self.port), callback_server_parameters=CallbackServerParameters(port=0))
python_port = self.gateway.get_callback_server().get_listening_port()
self.gateway.java_gateway_server.resetCallbackClient(
self.gateway.java_gateway_server.getCallbackClient().getAddress(), python_port)
self.manager = self.gateway.entry_point
# check if pipe built
if self.p1_server is None:
raise Exception("Must call build_pipe_and_return_p2 and also make p2 env after gym.make() but before env.reset()")
self.pipe = self.p1_server
if self.display:
self.p1 = GymAIDisplay(self.gateway, self.p1_client, self.frameskip)
self.p2 = GymAIDisplay(self.gateway, self.p2_client, self.frameskip)
else:
self.p1 = GymAI(self.gateway, self.p1_client, self.frameskip)
def _start_gateway(self, p2=Machete):
# auto select callback server port and reset it in java env
self.gateway = JavaGateway(gateway_parameters=GatewayParameters(
port=self.port), callback_server_parameters=CallbackServerParameters(port=0))
python_port = self.gateway.get_callback_server().get_listening_port()
self.gateway.java_gateway_server.resetCallbackClient(
self.gateway.java_gateway_server.getCallbackClient().getAddress(), python_port)
self.manager = self.gateway.entry_point
# create pipe between gym_env_api and python_ai for java env
server, client = Pipe()
self.pipe = server
self.p1 = GymAIDisplay(self.gateway, client, True)
self.manager.registerAI(self.p1.__class__.__name__, self.p1)
if isinstance(p2, str):
# p2 is a java class name
self.p2 = p2
self.game_to_start = self.manager.createGame(
def __init__(self):
print "calling constructor"
#launches java gateway server.
GateWayServer.launch_gateway()
print "attempting to connect to py4j gateway"
time.sleep(120)
self.gateway = JavaGateway(eager_load=True)
self.tokenizer = self.gateway.entry_point.getIXATokenizer()