Skip to content

Commit

Permalink
Test that sys.exit works in a Python script
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrueden committed Sep 26, 2024
1 parent 177bb42 commit da3b382
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/test/java/org/apposed/appose/ApposeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,28 @@ public void testStartupCrash() throws InterruptedException, IOException {
assertEquals(expectedLines, service.errorLines());
}

@Test
public void testPythonSysExit() throws InterruptedException, IOException {
Environment env = Appose.system();
try (Service service = env.python()) {
maybeDebug(service);

// Create a task that calls sys.exit. This is a nasty thing to do
// because Python does not exit the worker process when sys.exit is
// called within a dedicated threading.Thread; the thread just dies.
// So in addition to testing the Java code here, we are also testing
// that Appose's python_worker handles this situation well.
Task task = service.task("import sys\nsys.exit(123)");

// Launch the task and wait for it to finish.
task.waitFor();

// Is the tag flagged as failed due to thread death?
assertSame(TaskStatus.FAILED, task.status);
assertEquals("thread death", task.error);
}
}

@Test
public void testCrashWithActiveTask() throws InterruptedException, IOException {
Environment env = Appose.system();
Expand Down

0 comments on commit da3b382

Please sign in to comment.