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

Add method to terminate SbDut #256

Merged
merged 5 commits into from
Aug 20, 2024
Merged
Changes from 3 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
35 changes: 35 additions & 0 deletions switchboard/sbdut.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from .cmdline import get_cmdline_args

import siliconcompiler
import signal

SB_DIR = sb_path()

Expand Down Expand Up @@ -216,6 +217,7 @@ def __init__(
# initialization

self.intfs = {}
self.subprocess_list = []

# simulator-agnostic settings

Expand Down Expand Up @@ -614,10 +616,43 @@ def simulate(
args=plusargs_to_args(plusargs) + args
)

# Add newly created Popen object to subprocess list
self.subprocess_list.append(p)

# return a Popen object that one can wait() on

return p

def terminate(
azaidy marked this conversation as resolved.
Show resolved Hide resolved
self,
stop_timeout=10,
use_sigint=False
):
if not self.subprocess_list:
raise Exception('No ongoing simulation.'
'Please call simulate before trying to terminate.')
azaidy marked this conversation as resolved.
Show resolved Hide resolved

for p in self.subprocess_list:
poll = p.poll()
if poll is not None:
# process has stopped
return

if use_sigint:
try:
p.send_signal(signal.SIGINT)
p.wait(stop_timeout)
return
except: # noqa: E722
# if there is an exception for any reason, including
# Ctrl-C during the wait() call, want to make sure
# that the process is actually terminated
pass

# if we get to this point, the process is still running
# and sigint didn't work (or we didn't try it)
p.terminate()

def input_analog(
self,
filename: str,
Expand Down