Skip to content

Commit

Permalink
Merge pull request #1903 from OpenC3/no_script_zombies
Browse files Browse the repository at this point in the history
Eliminate script zombies. Fix python output thread. Default CI to empty string
  • Loading branch information
ryanmelt authored Feb 17, 2025
2 parents fe738c3 + f187935 commit 265fa8a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
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
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:
self.handle_output_io()
if RunningScript.cancel_output:
break
Expand Down

0 comments on commit 265fa8a

Please sign in to comment.