Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Dennis Ritchie is twice as bright as Steve Jobs, and only half wrong. -- Jim Gettys


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.22.1697904623.3828.python-list@python.org>

  copy mid

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

  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 18:10:19 +0200
Lines: 56
Message-ID: <mailman.22.1697904623.3828.python-list@python.org>
References: <CACwCsY44DNAJDZbD20bfycRQ6yr5LK1bR_RLw_x+Z2qfqP-ayA@mail.gmail.com>
<20231021154938.752713ae@jupiter>
<CACwCsY4NHJZB5L9Xg4kzUGrdG+Va938e5XipqJYik8m8qnCjQg@mail.gmail.com>
<20231021181019.61d1b3e0@jupiter>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de OAeCvytGdLZEcdxNarwejQwFA6O0RHQ9/IZomUavMbMA==
Cancel-Lock: sha1:YzoRUd8h/vep2pvjoM83SczG5HU= sha256:+Jai+E7v3pHw5tQNpt5MF6aK+0gygkuf2vIAQyi+3wo=
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=F7Is/NbJ;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'this:': 0.03; 'argument':
0.04; '2023': 0.07; 'e.g.': 0.07; 'that?': 0.07; 'cc:addr:python-
list': 0.09; 'example.': 0.09; 'way?': 0.09; 'cc:no real
name:2**0': 0.14; 'import': 0.15; 'that.': 0.15; 'invoke': 0.16;
'proc': 0.16; 'script,': 0.16; 'script.': 0.16; 'sounds': 0.16;
'wrote:': 0.16; 'python': 0.16; 'cc:addr:python.org': 0.20;
'sat,': 0.22; 'run': 0.23; 'actual': 0.25; 'cc:2**0': 0.25;
'seems': 0.26; 'python-list': 0.32; 'but': 0.32; 'there': 0.33;
'path': 0.33; 'script': 0.33; 'windows': 0.34; 'header:In-Reply-
To:1': 0.34; 'running': 0.34; 'runs': 0.35; 'missing': 0.37;
'using': 0.37; 'file': 0.38; 'way': 0.38; 'could': 0.38; 'use':
0.39; 'want': 0.40; 'best': 0.61; 'your': 0.64; 'manually': 0.69;
'received:5': 0.69; 'reliable': 0.74; 'activate': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hanez.org; s=dkim;
t=1697904620; h=from:subject:date:message-id:to:cc:mime-version:content-type:
content-transfer-encoding:in-reply-to:references;
bh=t6SBKrdztODxZHN6arOKFhrd9bL2hJf1QxQFqVEEV2A=;
b=F7Is/NbJkLeN63QEFJ9efyC3JYI4m2yEK0QIakNZoT0IHfocaAR+cAvZVQxV61xFcmDcIj
EhNFERQp3jxDHC6jEz49SqPTKyMn10TvvU5mSYq8sSsUW5AsnH1u/ony79xP8vkJ9oys9R
CaFb11EpbNVoq6lxdOpj6/DeLDwvCWgM414sjb3uMTRnYirpqp0rRjMZETO1Nem5wpnedf
Cf2kup7tLMqG7N4kO9pNBZF31p1hn/8DWQhDdbFuIRm4v4cICQhcBC7/31LpKuZf6E79yc
tbF5dWCkyNyL5b7hEjQqLocXEncum0mMbgI8lfupNLjgO+ikxQfFwDM6QyQm9A==
In-Reply-To: <CACwCsY4NHJZB5L9Xg4kzUGrdG+Va938e5XipqJYik8m8qnCjQg@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: <20231021181019.61d1b3e0@jupiter>
X-Mailman-Original-References: <CACwCsY44DNAJDZbD20bfycRQ6yr5LK1bR_RLw_x+Z2qfqP-ayA@mail.gmail.com>
<20231021154938.752713ae@jupiter>
<CACwCsY4NHJZB5L9Xg4kzUGrdG+Va938e5XipqJYik8m8qnCjQg@mail.gmail.com>
 by: Johannes Findeisen - Sat, 21 Oct 2023 16:10 UTC

On Sat, 21 Oct 2023 11:32:03 -0400
Larry Martell <larry.martell@gmail.com> wrote:

> On Sat, Oct 21, 2023 at 9:49 AM Johannes Findeisen
> <mailman@hanez.org> wrote:
> >
> > 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?
>
> How? Open a file and write the commands I need then invoke 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" rel="nofollow" target="_blank">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
>
> I know how to use Popen. What I was missing was running the script
> using sys.executable. Thanks.

sys.executable is the path to the actual Python binary, e.g.
"/usr/bin/python". You could add "/usr/bin/python" there manually but
this is not portable to Windows for example.

When you add a shebang line to your other script and the file is
executable, you may not need to add sys.executable as first argument to
Popen but using sys.executable is the most reliable way to do this... ;)

Regards,
Johannes

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor