本文整理汇总了Python中py4j.java_gateway.JavaGateway.shutdown_callback_server方法的典型用法代码示例。如果您正苦于以下问题:Python JavaGateway.shutdown_callback_server方法的具体用法?Python JavaGateway.shutdown_callback_server怎么用?Python JavaGateway.shutdown_callback_server使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类py4j.java_gateway.JavaGateway
的用法示例。
在下文中一共展示了JavaGateway.shutdown_callback_server方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import shutdown_callback_server [as 别名]
#.........这里部分代码省略.........
else:
# LIVY-294, need to check whether HiveContext can work properly,
# fallback to SQLContext if HiveContext can not be initialized successfully.
# Only for spark-1.
code = textwrap.dedent("""
import py4j
from pyspark.sql import SQLContext
try:
sqlContext.tables()
except py4j.protocol.Py4JError:
sqlContext = SQLContext(sc)""")
exec(code, global_dict)
#Start py4j callback server
from py4j.protocol import ENTRY_POINT_OBJECT_ID
from py4j.java_gateway import JavaGateway, GatewayClient, CallbackServerParameters
gateway_client_port = int(os.environ.get("PYSPARK_GATEWAY_PORT"))
gateway = JavaGateway(GatewayClient(port=gateway_client_port))
gateway.start_callback_server(
callback_server_parameters=CallbackServerParameters(port=0))
socket_info = gateway._callback_server.server_socket.getsockname()
listening_port = socket_info[1]
pyspark_job_processor = PySparkJobProcessorImpl()
gateway.gateway_property.pool.dict[ENTRY_POINT_OBJECT_ID] = pyspark_job_processor
global local_tmp_dir_path, job_context
local_tmp_dir_path = tempfile.mkdtemp()
job_context = JobContextImpl()
print(sys.stdout.getvalue(), file=sys_stderr)
print(sys.stderr.getvalue(), file=sys_stderr)
clearOutputs()
print('READY(port=' + str(listening_port) + ')', file=sys_stdout)
sys_stdout.flush()
while True:
line = sys_stdin.readline()
if line == '':
break
elif line == '\n':
continue
try:
msg = json.loads(line)
except ValueError:
LOG.error('failed to parse message', exc_info=True)
continue
try:
msg_type = msg['msg_type']
except KeyError:
LOG.error('missing message type', exc_info=True)
continue
try:
content = msg['content']
except KeyError:
LOG.error('missing content', exc_info=True)
continue
if not isinstance(content, dict):
LOG.error('content is not a dictionary')
continue
try:
handler = msg_type_router[msg_type]
except KeyError:
LOG.error('unknown message type: %s', msg_type)
continue
response = handler(content)
try:
response = json.dumps(response)
except ValueError:
response = json.dumps({
'msg_type': 'inspect_reply',
'content': {
'status': 'error',
'ename': 'ValueError',
'evalue': 'cannot json-ify %s' % response,
'traceback': [],
}
})
print(response, file=sys_stdout)
sys_stdout.flush()
finally:
if os.environ.get("LIVY_TEST") != "true" and 'sc' in global_dict:
gateway.shutdown_callback_server()
shutil.rmtree(local_tmp_dir_path)
global_dict['sc'].stop()
sys.stdin = sys_stdin
sys.stdout = sys_stdout
sys.stderr = sys_stderr