Skip to content

Commit e04637e

Browse files
byllyfishfantix
andauthored
create_subprocess_exec should treat env={} as empty environment (#439) (#454)
* Empty env dict represents empty environment. * Allow 0-length cstring array Co-authored-by: Fantix King <[email protected]>
1 parent e7934c8 commit e04637e

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

‎tests/test_process.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@ async def test():
5050

5151
self.loop.run_until_complete(test())
5252

53+
deftest_process_env_2(self):
54+
asyncdeftest():
55+
cmd='env'
56+
env={} # empty environment
57+
proc=awaitasyncio.create_subprocess_exec(
58+
cmd,
59+
env=env,
60+
stdout=subprocess.PIPE,
61+
stderr=subprocess.PIPE)
62+
63+
out, _=awaitproc.communicate()
64+
self.assertEqual(out, b'')
65+
self.assertEqual(proc.returncode, 0)
66+
67+
self.loop.run_until_complete(test())
68+
5369
deftest_process_cwd_1(self):
5470
asyncdeftest():
5571
cmd='pwd'

‎uvloop/handles/process.pyx‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,6 @@ cdef class UVProcess(UVHandle):
217217

218218
char**ret
219219

220-
if UVLOOP_DEBUG:
221-
assert arr_len >0
222-
223220
ret =<char**>PyMem_RawMalloc((arr_len +1) * sizeof(char*))
224221
if ret isNULL:
225222
raiseMemoryError()
@@ -285,7 +282,7 @@ cdef class UVProcess(UVHandle):
285282
self.uv_opt_args =self.__to_cstring_array(self.__args)
286283

287284
cdef _init_env(self, dict env):
288-
if env isnotNoneandlen(env):
285+
if env isnotNone:
289286
self.__env =list()
290287
for key in env:
291288
val = env[key]

0 commit comments

Comments
(0)