0
0
Intro to Computingfundamentals~10 mins

Process management (running programs) in Intro to Computing - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start a new process in Python using the subprocess module.

Intro to Computing
import subprocess
subprocess.[1](['echo', 'Hello World'])
Drag options to blanks, or click blank then click option'
Alaunch
Brun
Cexecute
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'start' instead of 'run' causes an AttributeError.
Using 'execute' or 'launch' are not valid subprocess functions.
2fill in blank
medium

Complete the code to create a new process that runs a Python script asynchronously.

Intro to Computing
import subprocess
process = subprocess.[1](['python3', 'script.py'])
Drag options to blanks, or click blank then click option'
Aexecute
Brun
Ccall
DPopen
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'run' waits for the process to finish.
Using 'call' is similar to 'run' and waits.
3fill in blank
hard

Fix the error in the code that tries to terminate a running process.

Intro to Computing
import subprocess
proc = subprocess.Popen(['sleep', '10'])
proc.[1]()
Drag options to blanks, or click blank then click option'
Aterminate
Bend
Ckillall
Dstop
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'stop' or 'end' causes AttributeError.
Using 'killall' is not a method of Popen objects.
4fill in blank
hard

Fill both blanks to check if a process has finished and get its exit code.

Intro to Computing
import subprocess
proc = subprocess.Popen(['ls'])
if proc.[1]() is not None:
    exit_code = proc.[2]
Drag options to blanks, or click blank then click option'
Apoll
Bwait
Creturncode
Dexit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'wait' in first blank blocks until process ends.
Using 'exit' is not a valid attribute or method.
5fill in blank
hard

Fill all three blanks to start a process, wait for it to finish, and capture its output.

Intro to Computing
import subprocess
result = subprocess.[1](['echo', 'Hello'], capture_output=[2], text=[3])
print(result.stdout)
Drag options to blanks, or click blank then click option'
Arun
BTrue
CFalse
DPopen
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Popen' does not capture output by default.
Setting capture_output or text to False returns bytes or no output.