Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions py4j-python/src/py4j/clientserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,15 @@ def garbage_collect_object(self, target_id, enqueue=True):
JavaObject on the Python side. If enqueue is True, sends the request
to the FinalizerWorker deque. Otherwise, sends the request to the Java
side.

When this ``JavaClient`` was constructed without a
``finalizer_deque`` (which can happen on subclasses or in test
harnesses — see ``InstrJavaClient`` in ``tests/instrumented.py``),
there is no worker thread to drain the deque, so we fall back to
the synchronous super-class implementation regardless of
``enqueue``.
"""
if enqueue:
if enqueue and self.finalizer_deque is not None:
self.finalizer_deque.appendleft((self, target_id))
else:
super().garbage_collect_object(target_id)
Expand All @@ -250,7 +257,17 @@ def shutdown_gateway(self):
try:
super().shutdown_gateway()
finally:
self.finalizer_deque.appendleft(SHUTDOWN_FINALIZER_WORKER)
# The SHUTDOWN sentinel only makes sense if there's a
# ``FinalizerWorker`` consuming from the deque (i.e. this
# ``JavaClient`` was wired by a full ``ClientServer``). When
# constructed without a ``finalizer_deque`` — e.g. by an
# ``InstrJavaClient`` test subclass that does not propagate
# the kwarg — there is no worker to signal and the
# post-shutdown ``appendleft`` would raise ``AttributeError``
# on the ``None`` deque. Guard the post-condition so the
# ``finally`` is safe regardless of construction path.
if self.finalizer_deque is not None:
self.finalizer_deque.appendleft(SHUTDOWN_FINALIZER_WORKER)

def get_thread_connection(self):
"""Returns the ClientServerConnection associated with this thread. Can
Expand Down
Loading
Loading