Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Without followers, evil cannot spread. -- Spock, "And The Children Shall Lead", stardate 5029.5


devel / comp.lang.python / Re: Running a subprocess in a venv

SubjectAuthor
o Re: Running a subprocess in a venvJohannes Findeisen

1
Re: Running a subprocess in a venv

<mailman.19.1697896570.3828.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24157&group=comp.lang.python#24157

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: mail...@hanez.org (Johannes Findeisen)
Newsgroups: comp.lang.python
Subject: Re: Running a subprocess in a venv
Date: Sat, 21 Oct 2023 15:49:38 +0200
Lines: 29
Message-ID: <mailman.19.1697896570.3828.python-list@python.org>
References: <CACwCsY44DNAJDZbD20bfycRQ6yr5LK1bR_RLw_x+Z2qfqP-ayA@mail.gmail.com>
<20231021154938.752713ae@jupiter>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de S64OBIkAT1BzMrqIu8csowDeCxvxtnoFT0jq2FgzOAXg==
Cancel-Lock: sha1:sVlsrOzh5fLtpSnJJwnpy/4JNVs= sha256:Mmc8vuoPnXXu6JXjJtFxjdnc7rCmLg9W2anpxZMEL58=
Return-Path: <mailman@hanez.org>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=hanez.org header.i=@hanez.org header.b=fiI12TI6;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.007
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'this:': 0.03; '2023':
0.07; 'that?': 0.07; 'way?': 0.09; 'import': 0.15; 'proc': 0.16;
'script,': 0.16; 'script.': 0.16; 'sounds': 0.16; 'wrote:': 0.16;
'python': 0.16; 'to:addr:python-list': 0.20; 'sat,': 0.22; 'run':
0.23; 'cc:2**0': 0.25; 'seems': 0.26; 'python-list': 0.32; 'but':
0.32; 'there': 0.33; 'script': 0.33; 'header:In-Reply-To:1': 0.34;
'runs': 0.35; 'file': 0.38; 'way': 0.38; 'could': 0.38; 'want':
0.40; 'best': 0.61; 'your': 0.64; 'received:5': 0.69; 'activate':
0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hanez.org; s=dkim;
t=1697896179; h=from:subject:date:message-id:to:cc:mime-version:content-type:
content-transfer-encoding:in-reply-to:references;
bh=XjalIh1vrToD2IVipazaBeyvz6wkusSV+WDZ2U/7LvQ=;
b=fiI12TI6Xw34+ZBoU7RcFl6btEmClXZQKebMHpl2WFN+9E53az7YeScqkntp6YVk4t/oOB
0/LN3/xRjhKi+KCvHE452G7escb7isnOeycygVdav9OmU/9fWGUMjXDS9xqdn9tzNq9BP8
S1blzf1BKbthR22IdPiTDUVjoqwws2ymD8iaw8BreFFu53/mBS0IhzLLyavYTJ1iLMo3UD
ajjsSHGBVmR6rmEGJflhED+eiRx+2o3T4gL4E8D+F3RGiKTUuXlWLUHoY6YOEQG1acf4qQ
dNg/ZFY1yLK9YQpDxapU4EPK+8H3E0a0xyzlBpV+jX7b4BJH03jN9wio98Rsvw==
In-Reply-To: <CACwCsY44DNAJDZbD20bfycRQ6yr5LK1bR_RLw_x+Z2qfqP-ayA@mail.gmail.com>
X-Last-TLS-Session-Version: TLSv1.3
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <20231021154938.752713ae@jupiter>
X-Mailman-Original-References: <CACwCsY44DNAJDZbD20bfycRQ6yr5LK1bR_RLw_x+Z2qfqP-ayA@mail.gmail.com>
 by: Johannes Findeisen - Sat, 21 Oct 2023 13:49 UTC

On Sat, 21 Oct 2023 09:01:18 -0400
Larry Martell via Python-list <python-list@python.org> wrote:

> I have a python script, and from that I want to run another script in
> a subprocess in a venv. What is the best way to do that? I could write
> a file that activates the venv then runs the script, then run that
> file, but that seems messy. Is there a better way?

How do you do that? It sounds messy but not wrong...

I would activate the venv and then run my Python script. In the Python
script you can call another python script in a subprocess like this:

import sys
import subprocess

# https://docs.python.org/3/library/subprocess.html#popen-constructor
proc = subprocess.Popen([sys.executable, "/path/to/an/otherscript.py"])

# https://docs.python.org/3/library/subprocess.html#popen-objects
# Do your process communication/handling... proc.communicate(),
# proc.wait(), proc.terminate(), proc.kill() etc.

Is this the answer you are looking for?

Detailed docs: https://docs.python.org/3/library/subprocess.html

Regards,
Johannes

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor