This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2011年12月03日 12:20 by Andrey.Morozov, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| run_me.py | Andrey.Morozov, 2011年12月03日 12:20 | |||
| test1.py | Andrey.Morozov, 2011年12月03日 12:22 | |||
| Messages (9) | |||
|---|---|---|---|
| msg148792 - (view) | Author: Andrey Morozov (Andrey.Morozov) | Date: 2011年12月03日 12:20 | |
run_me.py:
import subprocess, sys
e = {'PATH_TO_MY_APPS' : "path/to/my/apps"}
p = subprocess.Popen(sys.executable + " test1.py 123", env=e, shell=True, stdout=subprocess.PIPE)
print(p.stdout.readlines())
p.wait()
test1.py:
1: import sys, os
2: #import tempfile
3: print("hello : " + sys.platform + " PATH: " + os.environ['PATH_TO_MY_APPS'])
System:
Python 2.7.2 x64, Windows x64 7 Pro + SP1
Problem:
if I run python run_me.py then I see on my stdout:
['hello : win32 PATH: path/to/my/apps\r\n']
but if I uncomment line number 2 in test1.py and run python run_me.py then I see on my stdout :
C:\tmp\python_test>python run_me.py
Traceback (most recent call last):
File "test1.py", line 2, in <module>
import tempfile
File "C:\Python27\lib\tempfile.py", line 34, in <module>
from random import Random as _Random
File "C:\Python27\lib\random.py", line 883, in <module>
_inst = Random()
File "C:\Python27\lib\random.py", line 97, in __init__
self.seed(x)
File "C:\Python27\lib\random.py", line 111, in seed
a = long(_hexlify(_urandom(16)), 16)
WindowsError: [Error -2146893818] Invalid Signature
[]
|
|||
| msg148793 - (view) | Author: Andrey Morozov (Andrey.Morozov) | Date: 2011年12月03日 12:22 | |
WIDW ? |
|||
| msg148795 - (view) | Author: Tim Golden (tim.golden) * (Python committer) | Date: 2011年12月03日 12:30 | |
The environment passed to a Windows process must contain certain things. (I don't at this moment remember exactly what). You can't just pass the one thing you're adding. Change your "e = ..." line to something like: e = os.environ e['PATH_TO_MY_CODE'] = '/x/y/z' and then try the code. Obviously the subprocess module doesn't have enough checks in place for this -- it actually segfaults on my WinXP machine. But can you confirm that this is indeed your issue? |
|||
| msg148796 - (view) | Author: Andrey Morozov (Andrey.Morozov) | Date: 2011年12月03日 12:34 | |
it fix my problem: e = os.environ.copy() e['PATH_TO_MY_APPS'] = "path/to/my/apps" p = subprocess.Popen(sys.executable + " test1.py 123", env=e, shell=True, stdout=subprocess.PIPE) answer: need have copy of environments |
|||
| msg148822 - (view) | Author: Tim Golden (tim.golden) * (Python committer) | Date: 2011年12月03日 22:16 | |
Re-opening because there's a real problem here which can crash Python hard. Simplest reproduction:
import sys
import subprocess
subprocess.Popen (sys.executable, env={})
Affects 2.x and 3.x tip (haven't tried others yet but I don't imagine it's different)
|
|||
| msg148823 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2011年12月03日 22:17 | |
> Re-opening because there's a real problem here which can crash Python > hard. Works under Linux. Is it Windows-specific? |
|||
| msg148824 - (view) | Author: Tim Golden (tim.golden) * (Python committer) | Date: 2011年12月03日 22:18 | |
Yes. I've added the "Windows" component on the tracker. (At least I think I have). It's to do with CreateProcess needing at least certain items in the environment passed. I'm trying to track down some docs on MSDN which specify which must be there. |
|||
| msg148850 - (view) | Author: Tim Golden (tim.golden) * (Python committer) | Date: 2011年12月04日 10:41 | |
OK, the long and short is that spwaning a process without passing in SystemRoot is asking for trouble. There's a blog post here which gives an example: http://jpassing.com/2009/12/28/the-hidden-danger-of-forgetting-to-specify-systemroot-in-a-custom-environment-block/ And, certainly this works: import os import subprocess subprocess.Popen( "notepad.exe", env={"SystemRoot" : os.environ['SystemRoot']} ) I'm not quite sure what approach we should take in the subprocess module. Is it a docs warning? Should we refuse to proceed if there's no SystemRoot? Is it the caller's responsibility? I'll ask on python-dev to gather opinions. |
|||
| msg148877 - (view) | Author: Tim Golden (tim.golden) * (Python committer) | Date: 2011年12月05日 15:51 | |
After a discussion on python-dev: http://mail.python.org/pipermail/python-dev/2011-December/114733.html I propose to close this call tomorrow as wontfix |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:24 | admin | set | github: 57733 |
| 2011年12月06日 09:58:09 | tim.golden | set | status: open -> closed resolution: wont fix |
| 2011年12月05日 15:51:39 | tim.golden | set | messages: + msg148877 |
| 2011年12月04日 10:41:34 | tim.golden | set | messages: + msg148850 |
| 2011年12月03日 22:18:41 | tim.golden | set | messages: + msg148824 |
| 2011年12月03日 22:17:40 | pitrou | set | versions:
- Python 3.1 nosy: + pitrou messages: + msg148823 stage: test needed -> |
| 2011年12月03日 22:16:08 | tim.golden | set | status: closed -> open messages: + msg148822 assignee: tim.golden components: + Library (Lib), Windows stage: test needed |
| 2011年12月03日 12:34:22 | Andrey.Morozov | set | status: open -> closed messages: + msg148796 |
| 2011年12月03日 12:30:05 | tim.golden | set | nosy:
+ tim.golden messages: + msg148795 |
| 2011年12月03日 12:22:57 | Andrey.Morozov | set | files:
+ test1.py messages: + msg148793 |
| 2011年12月03日 12:20:23 | Andrey.Morozov | create | |