I think you're looking for something more like the multiprocessing module:

http://docs.python.org/library/multiprocessing.html#the-process-class

The subprocess module is for spawning processes and doing things with their input/output - not for running functions.

Here is a multiprocessing version of your code:

from multiprocessing import Process, Queue

# must be a global function    
def my_function(q, x):
    q.put(x + 100)

if __name__ == '__main__':
    queue = Queue()
    p = Process(target=my_function, args=(queue, 1))
    p.start()
    p.join() # this blocks until the process terminates
    result = queue.get()
    print result
Answer from Brian McKenna on Stack Overflow
🌐
Python
docs.python.org › 3 › library › subprocess.html
subprocess — Subprocess management
1 week ago - ... Availability: not Android, not iOS, not WASI. This module is not supported on mobile platforms or WebAssembly platforms. The recommended approach to invoking subprocesses is to use the run() function ...
🌐
DataCamp
datacamp.com › tutorial › python-subprocess
An Introduction to Python Subprocess: Basics and Examples | DataCamp
September 12, 2025 - It's always a good practice to use the subprocess.run() function that allows you to specify various options for how the command should be run, such as whether to raise an exception if the command fails. If you are interested in doing a deep dive into endless possibilities for command line ...
Discussions

python - Is it possible to run function in a subprocess without threading or writing a separate file/script. - Stack Overflow
import subprocess def my_function(x): return x + 100 output = subprocess.Popen(my_function, 1) #I would like to pass the function object and its arguments print output #desired output: 101 I... More on stackoverflow.com
🌐 stackoverflow.com
How to use subprocess.run method in python? - Stack Overflow
I wanted to run external programs using python but I receive an error saying I don't have the file the code I wrote: import subprocess subprocess.run(["ls", "-l"]) Output: Tra... More on stackoverflow.com
🌐 stackoverflow.com
How subprocess run() works?
Running python sys.executable in pycharm shows it uses virtual environment interpreter (venv) PS C:\Users\SJ\Desktop\Programs\Python\PyTest> python Python 3.11.4 (tags/v3.11.4:d2340ef, Jun 7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" ... More on discuss.python.org
🌐 discuss.python.org
7
0
June 21, 2024
Using a Python subprocess call to invoke a Python script - Stack Overflow
Only *nix: using fork you will ... process python interpreter (with all existing imports, ...). If you want a brand new interpretor this not a good choice. See the diff fork/exec unix system call. 2011-08-23T02:46:22.58Z+00:00 ... subprocess module uses fork/exec on POSIX systems and CreateProcess on Windows. No need to use fork directly if you want to run a Python ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Python Morsels
pythonmorsels.com › running-subprocesses-in-python
Running subprocesses in Python - Python Morsels
March 6, 2025 - You can use Python's subprocess.run function to launch other programs from within Python.
🌐
Dataquest
dataquest.io › blog › python-subprocess
Python Subprocess: The Simple Beginner's Tutorial (2023)
February 19, 2025 - This possibility makes calling ... of the subprocess as a variable throughout the rest of the Python script, for instance. The module was first implemented in Python 2.4 with the goal of being an alternative to other functions, such as os.system. Also, since Python 3.5, the recommended usage for this module is through the run() function, ...
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-use-subprocess-to-run-external-programs-in-python-3
How To Use subprocess to Run External Programs in Python 3 | DigitalOcean
July 30, 2020 - I needed to use subprocess.run(“python3.6 mypython.py”, shell=True) to make it work. As stated, the beauty of sys.executable is the assurance of running the same python version as the one issuing the command. Do you know a way to set the “by default” python version used by the subprocess.run function?
🌐
Earthly
earthly.dev › blog › python-subprocess
How to Use Python's Subprocess Module - Earthly Blog
July 11, 2023 - The subprocess module is built into the Python standard library, so you can import it into your working environment: ... After importing the subprocess module, you can call the run() function with the syntax: subprocess.run(command) to run an ...
🌐
Real Python
realpython.com › python-subprocess
The subprocess Module: Wrapping Programs With Python – Real Python
January 18, 2025 - Most of your interaction with the Python subprocess module will be via the run() function.
Find elsewhere
🌐
Python Land
python.land › home › interaction with the operating system › python subprocess: run external commands
Python Subprocess: Run External Commands • Python Land Tutorial
October 30, 2024 - If the external command expects data on standard input, we can do so easily as well with the input option of Python’s subprocess.run function. Please note that I’m not going into streaming data here.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-subprocess-module
Python subprocess module - GeeksforGeeks
2 weeks ago - Popen starts a new process and allows interaction with it while it is running. It gives control over input, output and error streams. Example: In this example, a process is started and its output is captured.
🌐
Python 101
python101.pythonlibrary.org › chapter19_subprocess.html
Chapter 19 - The subprocess Module — Python 101 1.0 documentation
This function allows you to call another program, wait for the command to complete and then return the return code. It accepts one or more arguments as well as the following keyword arguments (with their defaults): stdin=None, stdout=None, stderr=None, shell=False.
🌐
Simplilearn
simplilearn.com › home › resources › software development › python subprocess: master external command execution
Python Subprocess: Master External Command Execution
December 15, 2025 - Learn about Python's subprocess module for executing external commands. Discover how to manage processes and handle inputs/outputs efficiently.
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
IONOS
ionos.com › digital guide › websites › web development › python subprocess
How to use Python subprocess to execute external commands and programs
June 27, 2025 - We will now use this function for our first small example to il­lus­trate how Python subprocess works. To do this, we first import the subprocess and sys modules and then execute a simple request. The cor­re­spond­ing code looks like this: import subprocess import sys result = subprocess.run([sys.executable, "-c", "print('hello')"])python
🌐
Codecademy
codecademy.com › article › python-subprocess-tutorial-master-run-and-popen-commands-with-examples
Python Subprocess Tutorial: Master run() and Popen() Commands (with Examples) | Codecademy
It can also raise an exception if the command fails, capture output to variables, or run commands via the system shell. This function is ideal for short, one-off shell tasks without advanced interaction, such as installing dependencies, listing files, or automating routine jobs. ... subprocess.run(args, *, stdin=None, input=None, stdout=None, stderr=None, capture_output=False, shell=False, cwd=None, timeout=None, check=False, encoding=None, errors=None, text=None, env=None, universal_newlines=None, **other_popen_kwargs)
🌐
Medium
medium.com › @techclaw › python-subprocess-run-ad2fcedde2d5
Python Subprocess Run. Introduction | by TechClaw | Medium
August 8, 2023 - The subprocess.run() function is a part of the subprocess module introduced in Python 3.5. It provides a simple and efficient way to spawn new processes, execute system commands, and interact with them.
🌐
Python Module of the Week
pymotw.com › 2 › subprocess
subprocess – Work with additional processes - Python Module of the Week
Instead, the function is passed to Popen as the preexec_fn argument so it is run after the fork() inside the new process, before it uses exec() to run the shell. import os import signal import subprocess import tempfile import time import sys script = '''#!/bin/sh echo "Shell script in process ...
🌐
Python for Network Engineers
pyneng.readthedocs.io › en › latest › book › 12_useful_modules › subprocess.html
subprocess - Python for network engineers
In Python 3.5, syntax of subprocess module has changed. Function subprocess.run() is the main way of working with subprocess module.