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

Executing Python script using subprocess.Popen twice interactively fails without error the second time #45866

Closed
canhuth mannequin opened this issue Nov 30, 2007 · 3 comments
Labels
OS-windows type-bug An unexpected behavior, bug, or error

Comments

@canhuth
Copy link
Mannequin

canhuth mannequin commented Nov 30, 2007

BPO 1525
Nosy @amauryfa

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2007-11-30.11:11:09.791>
created_at = <Date 2007-11-30.10:00:43.971>
labels = ['type-bug', 'invalid', 'OS-windows']
title = 'Executing Python script using subprocess.Popen twice interactively fails without error the second time'
updated_at = <Date 2007-11-30.11:29:39.092>
user = 'https://bugs.python.org/canhuth'

bugs.python.org fields:

activity = <Date 2007-11-30.11:29:39.092>
actor = 'canhuth'
assignee = 'none'
closed = True
closed_date = <Date 2007-11-30.11:11:09.791>
closer = 'amaury.forgeotdarc'
components = ['Windows']
creation = <Date 2007-11-30.10:00:43.971>
creator = 'canhuth'
dependencies = []
files = []
hgrepos = []
issue_num = 1525
keywords = []
message_count = 3.0
messages = ['57971', '57974', '57976']
nosy_count = 2.0
nosy_names = ['amaury.forgeotdarc', 'canhuth']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue1525'
versions = ['Python 2.5']

@canhuth
Copy link
Mannequin Author

canhuth mannequin commented Nov 30, 2007

Executing script using subprocess.Popen twice interactively fails
without error the second time. File a.py:

print "start"
import subprocess

print "first call"
process = subprocess.Popen(
args = "cmd.exe /c echo 1",
stdout = subprocess.PIPE)

for line in process.stdout:
	if not line:
		break;
	print line;

print "second call"
process = subprocess.Popen(
args = "cmd.exe /c echo 2",
stdout = subprocess.PIPE)

for line in process.stdout:
	if not line:
		break;
	print line;

print "end"

Executing it in Python on Windows, interactively:

Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import a
start
first call
1

second call
2

end
>>> import a
>>>

@canhuth canhuth mannequin added OS-windows type-bug An unexpected behavior, bug, or error labels Nov 30, 2007
@amauryfa
Copy link
Member

Top-level statements are executed only the first time the module is
imported:
http://docs.python.org/tut/node8.html#moreModules
To execute a script from python, you should consider the execfile()
function instead.

@canhuth
Copy link
Mannequin Author

canhuth mannequin commented Nov 30, 2007

Bah, silly me, I apologize, and thank you for the quick feedback.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-windows type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant