我尝试在我的 Jupyter 笔记本中运行这个简单的 Spark 会话创建命令 -
spark = SparkSession.builder.getOrCreate()
但是我不断收到以下错误:
---------------------------------------------------------------------------
ConnectionRefusedError Traceback (most recent call last)
Cell In[22], line 1
----> 1 spark = SparkSession.builder.getOrCreate()
File C:\Python\lib\site-packages\pyspark\sql\session.py:503, in SparkSession.Builder.getOrCreate(self)
500 session = SparkSession(sc, options=self._options)
501 else:
502 getattr(
--> 503 getattr(session._jvm, "SparkSession$"), "MODULE$"
504 ).applyModifiableSettings(session._jsparkSession, self._options)
505 return session
File C:\Python\lib\site-packages\py4j\java_gateway.py:1712, in JVMView.__getattr__(self, name)
1709 if name == UserHelpAutoCompletion.KEY:
1710 return UserHelpAutoCompletion()
-> 1712 answer = self._gateway_client.send_command(
1713 proto.REFLECTION_COMMAND_NAME +
1714 proto.REFL_GET_UNKNOWN_SUB_COMMAND_NAME + name + "\n" + self._id +
1715 "\n" + proto.END_COMMAND_PART)
1716 if answer == proto.SUCCESS_PACKAGE:
1717 return JavaPackage(name, self._gateway_client, jvm_id=self._id)
File C:\Python\lib\site-packages\py4j\java_gateway.py:1036, in GatewayClient.send_command(self, command, retry, binary)
1015 def send_command(self, command, retry=True, binary=False):
1016 """Sends a command to the JVM. This method is not intended to be
1017 called directly by Py4J users. It is usually called by
1018 :class:`JavaMember` instances.
(...)
1034 if `binary` is `True`.
1035 """
-> 1036 connection = self._get_connection()
1037 try:
1038 response = connection.send_command(command)
File C:\Python\lib\site-packages\py4j\clientserver.py:284, in JavaClient._get_connection(self)
281 pass
283 if connection is None or connection.socket is None:
--> 284 connection = self._create_new_connection()
285 return connection
File C:\Python\lib\site-packages\py4j\clientserver.py:291, in JavaClient._create_new_connection(self)
287 def _create_new_connection(self):
288 connection = ClientServerConnection(
289 self.java_parameters, self.python_parameters,
290 self.gateway_property, self)
--> 291 connection.connect_to_java_server()
292 self.set_thread_connection(connection)
293 return connection
File C:\Python\lib\site-packages\py4j\clientserver.py:438, in ClientServerConnection.connect_to_java_server(self)
435 if self.ssl_context:
436 self.socket = self.ssl_context.wrap_socket(
437 self.socket, server_hostname=self.java_address)
--> 438 self.socket.connect((self.java_address, self.java_port))
439 self.stream = self.socket.makefile("rb")
440 self.is_connected = True
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
但是,当我第一次运行这个命令时,它运行得很好,但几个小时后,上述错误变得持续存在。
我也有同样的问题。重新启动正在运行的内核解决了我的问题。
当我将电脑长时间置于睡眠模式然后尝试继续使用 Jupyter 笔记本时,似乎会发生这种情况。