本文整理汇总了Python中py4j.java_gateway.JavaGateway.start_callback_server方法的典型用法代码示例。如果您正苦于以下问题:Python JavaGateway.start_callback_server方法的具体用法?Python JavaGateway.start_callback_server怎么用?Python JavaGateway.start_callback_server使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类py4j.java_gateway.JavaGateway
的用法示例。
在下文中一共展示了JavaGateway.start_callback_server方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LazyStart
# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import start_callback_server [as 别名]
class LazyStart(unittest.TestCase):
def setUp(self):
self.p = start_example_app_process3()
self.gateway = JavaGateway(callback_server_parameters=CallbackServerParameters(eager_load=False))
def tearDown(self):
safe_shutdown(self)
self.p.join()
def testByteString(self):
try:
self.gateway.start_callback_server()
self.gateway.entry_point.test(B())
self.gateway.start_callback_server()
self.gateway.start_callback_server()
self.gateway.entry_point.test(B())
except Exception:
print_exc()
self.fail()
示例2: main
# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import start_callback_server [as 别名]
def main():
sys_stdin = sys.stdin
sys_stdout = sys.stdout
sys_stderr = sys.stderr
if sys.version >= '3':
sys.stdin = io.StringIO()
else:
sys.stdin = cStringIO.StringIO()
sys.stdout = UnicodeDecodingStringIO()
sys.stderr = UnicodeDecodingStringIO()
spark_major_version = os.getenv("LIVY_SPARK_MAJOR_VERSION")
try:
listening_port = 0
if os.environ.get("LIVY_TEST") != "true":
#Load spark into the context
exec('from pyspark.shell import sc', global_dict)
exec('from pyspark.shell import sqlContext', global_dict)
exec('from pyspark.sql import HiveContext', global_dict)
exec('from pyspark.streaming import StreamingContext', global_dict)
exec('import pyspark.cloudpickle as cloudpickle', global_dict)
if spark_major_version >= "2":
exec('from pyspark.shell import spark', global_dict)
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
#.........这里部分代码省略.........