pylint-errors

W1509 (subprocess-popen-preexec-fn)

:x: Problematic code:

import subprocess

proc = subprocess.Popen(
    ['ls', '/home'],
    preexec_fn=lambda: print('Some actions'),
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE
)

:heavy_check_mark: Correct code:

import subprocess

proc = subprocess.Popen(
    ['script.sh'],  # a path to a script that will do a pre command
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE
)

Rationale:

The preexec_fn parameter is not safe to use in the presence of threads in your application. The child process could deadlock before exec is called. If you must use it, keep it trivial! Minimize the number of libraries you call into.