Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug #325: Fix print output in @at_cleanup functions not appearing in node console #343

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
23 changes: 17 additions & 6 deletions nodel-jyhost/src/main/java/org/nodel/jyhost/PyNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -892,17 +892,28 @@ public void error(Object obj) {
*/
private void cleanupInterpreter() {
String message;

if (_python != null) {
message = "(closing this interpreter...)";

_logger.info(message);
_outReader.inject(message);

try {
// Ensure the PySystemState is set before executing cleanup functions
PySystemState systemState = _python.getSystemState();
if (systemState == null)
throw new IllegalStateException("Python interpreter not ready.");

Py.setSystemState(systemState);

// Reassign the output streams
_python.setOut(_outReader);
_python.setErr(_errReader);

PyFunction processCleanupFunctions = (PyFunction) _globals.get(Py.java2py("processCleanupFunctions"));
long cleanupFnCount = processCleanupFunctions.__call__().asLong();

if (cleanupFnCount > 0) {
message = "('@at_cleanup' function" + (cleanupFnCount == 1 ? "" : "s") + " completed.)";
_logger.info(message);
Expand All @@ -912,14 +923,14 @@ private void cleanupInterpreter() {
// upstream exception handling should mean we never get here, but just in case
_logger.warn("Unexpected exception during cleaning up; should be safe to ignore", exc);
}

_python.cleanup();

message = "(clean up complete)";
_logger.info(message);
_outReader.inject(message);
}

if (_toolkit != null) {
_toolkit.shutdown();
}
Expand Down