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

Eliminate script zombies. Fix python output thread. Default CI to empty string #1903

Merged
merged 1 commit into from
Feb 17, 2025
Merged
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
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ SECRET_KEY_BASE=bdb4300d46c9d4f116ce3dbbd54cac6b20802d8be1c2333cf5f6f90b1627799a
OPENC3_CLOUD=local
# Change to arn:aws-us-gov for deploying to AWS Gov Cloud
OPENC3_AWS_ARN_PREFIX=arn:aws
# Default to not CI - blank string
CI=""

# This can be used to set the default language for generators
# OPENC3_LANGUAGE=ruby
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ def self.spawn(scope, name, suite_runner = nil, disconnect = false, environment
process.environment['RUBYOPT'] = nil # Removes loading bundler setup
process.environment['OPENC3_SCOPE'] = scope

process.detach = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prevents zombie processes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Detaching means that the spawning process is not responsible for waiting for the child to die and check the exit status.

process.start
running_script_id
end
Expand Down
6 changes: 4 additions & 2 deletions openc3-cosmos-script-runner-api/scripts/running_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def __init__(self, id, scope, name, disconnect):
self.output_time = datetime.now(timezone.utc).strftime(
RunningScript.STRFTIME_FORMAT
)
self.output_time_value = time.time()
self.state = "init"
self.script_globals = globals()
RunningScript.disconnect = disconnect
Expand Down Expand Up @@ -676,6 +677,7 @@ def handle_output_io(self, filename=None, line_number=None):
self.output_time = datetime.now(timezone.utc).strftime(
RunningScript.STRFTIME_FORMAT
)
self.output_time_value = time.time()
string = self.output_io.getvalue()
self.output_io.truncate(0)
self.output_io.seek(0)
Expand Down Expand Up @@ -976,7 +978,7 @@ def run_thread_body(
# Start Output Thread
if not RunningScript.output_thread:
RunningScript.output_thread = threading.Thread(
target=RunningScript.output_thread_body, daemon=True
target=RunningScript.output_thread_body, args=[self], daemon=True
)
RunningScript.output_thread.start()

Expand Down Expand Up @@ -1223,7 +1225,7 @@ def output_thread_body(self):
while True:
if RunningScript.cancel_output:
break
if (time.time() - self.output_time) > 5.0:
if (time.time() - self.output_time_value) > 5.0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did my refactor break this or was it always broke?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know.

self.handle_output_io()
if RunningScript.cancel_output:
break
Expand Down
Loading