def spawnProcessAndNullifyStdout(protocol, args):
""""Utility function to spawn a process and redirect stdout to /dev/null.
Spawns the process with the specified `protocol` in the reactor, with the
specified list of binary `args`.
"""
# Using childFDs we arrange for the child's stdout to go to /dev/null
# and for stderr to be read asynchronously by the reactor.
with open(os.devnull, "r+b") as devnull:
# This file descriptor to /dev/null will be closed before the
# spawned process finishes, but will remain open in the spawned
# process; that's the Magic Of UNIX™.
reactor.spawnProcess(
protocol, args[0], args, childFDs={
0: devnull.fileno(),
1: devnull.fileno(),
2: 'r'
},
env=select_c_utf8_bytes_locale())
评论列表
文章目录