Deadlocks caused by improper multiprocessing API usage
Invoking improper multiprocessing APIs with the wrong parameters might lead to a deadlock. The deadlock can result when the child process generates enough output to block the OS pipe buffer and waits for it to accept more data.
def deadlock_prevention_noncompliant():
    from subprocess import Popen, PIPE
    process = Popen('sh ~/example.sh', stdout=PIPE)
    # Noncompliant: uses the 'Popen.wait' with 'stdout=PIPE' or 'stderr=PIPE',
    # resulting in a potential deadlock and busy loop.
    process.wait()
    print(process.returncode)
def deadlock_prevention_compliant():
    from subprocess import Popen, PIPE
    process = Popen('sh ~/example.sh', stdout=PIPE)
    # Compliant: uses 'Popen.communicate' method, avoiding a
    # potential deadlock and busy loop.
    process.communicate()[0]
    print(process.returncode)