Comments (7)
Sorry for the delay. You probably need to investigate how to properly destroy the underlying process.
But with a continuous process like top, a background process keeps running.
Could you please provide more details what you mean that a background process keeps running? For me, process.destroyForcibly()
sends SIGKILL
on Unix, so the top
process is terminated.
from jediterm.
Let me describe my observation in detail:
-
opening a dialog with Jediterm inside (but without executing any shell command), then closing the dialog works and the whole swing application closes.
-
same as above, but executing a shell command, which terminates/exits (e. g.
ls
,pwd
,echo ...
) and then closing the dialog leaves the swing application open (the dialog closes but not all objects get destroyed). -
same as above, but with a continuously running shell command ( e. g.
top
) also prevents the swing application from closing.
I would understand use case 3, but even use case 2 prevents the swing application from exit?!
Even an exit
command into the shell before closing will not help.
from jediterm.
Thanks for clarification. Unfortunately, it is not reproduced for me on macOS using the steps:
- Clone this repo
- Replace JediTermMain.kt#L81-L82 with a single line
arrayOf("top")
- Run the application:
./gradlew :JediTerm:run
. A Swing application is opened withtop
command inside. - Close the application frame with mouse. The application is closed as expected.
If it are observing a different behavior, could you please provide a small example project with details how to reproduce it locally?
from jediterm.
If it are observing a different behavior, could you please provide a small example project with details how to reproduce it locally?
Sorry for late response, please see below.
When closing without calling a OS command, the Application terminates as expected. But when closing after calling any OS command (e. g. ls
or top
) it does not terminate and stays with a thread running.
package com.manticore.ui;
import com.jediterm.pty.PtyProcessTtyConnector;
import com.jediterm.terminal.TtyConnector;
import com.jediterm.terminal.ui.JediTermWidget;
import com.jediterm.terminal.ui.TerminalWidget;
import com.jediterm.terminal.ui.TerminalWidgetListener;
import com.jediterm.terminal.ui.UIUtil;
import com.jediterm.terminal.ui.settings.DefaultSettingsProvider;
import com.manticore.swingui.MDialog;
import com.pty4j.PtyProcess;
import com.pty4j.PtyProcessBuilder;
import org.junit.jupiter.api.Test;
import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
class AdminPanelTest {
public final static Logger LOGGER = Logger.getLogger(AdminPanelTest.class.getName());
public static void main(String[] args){
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
Map<String, String> envs = System.getenv();
String[] command;
if (UIUtil.isWindows) {
command = new String[] {"cmd.exe"};
} else {
command = new String[] {"/bin/sh", "--login"};
envs = new HashMap<>(System.getenv());
envs.put("TERM", "xterm-256color");
}
PtyProcess process =
new PtyProcessBuilder().setCommand(command).setEnvironment(envs).start();
TtyConnector connector = new PtyProcessTtyConnector(process, StandardCharsets.UTF_8);
JediTermWidget widget = new JediTermWidget(80, 24, new DefaultSettingsProvider());
widget.setTtyConnector(connector);
widget.start();
JDialog dialog = new JDialog();
dialog.add(widget);
dialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
if (widget.isSessionRunning()) {
widget.stop();
widget.close();
}
if (connector.isConnected()) {
connector.close();
}
if (process.isAlive()) {
process.destroyForcibly();
}
if (dialog.isShowing()) {
dialog.setVisible(false);
}
}
});
widget.addListener(new TerminalWidgetListener() {
@Override
public void allSessionsClosed(TerminalWidget terminalWidget) {
if (widget.isSessionRunning()) {
widget.stop();
widget.close();
}
if (connector.isConnected()) {
connector.close();
}
if (process.isAlive()) {
process.destroyForcibly();
}
if (dialog.isShowing()) {
dialog.setVisible(false);
}
}
});
dialog.setDefaultCloseOperation(MDialog.DISPOSE_ON_CLOSE);
dialog.setModal(false);
dialog.pack();
dialog.setVisible(true);
} catch (Exception ex) {
LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
}
}
});
}
}
from jediterm.
4. Close the application frame with mouse. The application is closed as expected.
I believe, this is achieved by forcefully setting the Frame.EXIT_ON_CLOSE
which is shading the underlying problem of a rouge thread kept running somewhere.
Of course, I could always call System.exit()
-- but that is not desirable in a Multi-User/Application Server scenario.
from jediterm.
@manticore-projects Thanks, reproduced. Fixed by a7670d9. Please see the updated BasicTerminalShellExample.java. Now JVM should exit gracefully on closing the window with mouse or on exiting the terminal session (Ctrl+D
or exit
).
from jediterm.
Thank you so much for looking into and fixing it. I do appreciate.
Cheers.
from jediterm.
Related Issues (20)
- use escape sequence to change cursor shape inside zsh causes character under the cursor becomes invisible
- Any way to set current working directory? HOT 3
- Broken terminal when launched from iTerm and powerlevel10k's transient prompt HOT 4
- How can I set the background color to be transparent? HOT 1
- UserSettingsProvider#getSelectionColor() is called way too often HOT 4
- Would you like to provide a demo? HOT 1
- Can I get the out without a ui page? HOT 13
- Clearing the buffer causes "Attempt to get line out of bounds" errors HOT 1
- Soft terminal reset clears screen content
- Please set the Java Tool chain in core/build.gradle HOT 6
- BASH 4.2 vs. Jeditterm 3.36 and newer HOT 4
- Solve split packages problem for running JediTerm on JPMS HOT 7
- com.jediterm.terminal.model.TerminalTextBuffer.lock freezes UI thread for 65seconds HOT 1
- Possible bug in AwtMouseWheelEvent
- Processing ESC key is very slow
- Clearing buffer via context menu gives error
- CTRL + BACKSPACE == BACKSPACE in showkey -a
- Color palette for sub application is not supported
- Question - How to increase line height? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jediterm.