NeuralEnsemble / PyNN

A Python package for simulator-independent specification of neuronal network models.
Other
276 stars 126 forks source link

update subprocess call in setup.py #730

Closed appukuttan-shailesh closed 3 years ago

appukuttan-shailesh commented 3 years ago

Fixes installation problem on Windows systems.

Currently users might see the installation getting stuck on running pip install pyNN or locally python setup.py install

Gets stuck at this stage: image

This arises from this method in setup.py

def run_command(path, working_directory):
    p = subprocess.Popen(path, shell=True, stdin=subprocess.PIPE,
                         stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
                         universal_newlines=True,
                         cwd=working_directory)
    result = p.wait()
    stdout = p.stdout.readlines()
    return result, stdout

On investigating, it was found that the execution gets stuck at result = p.wait()

The use of wait() is potentially problematic. As mentioned in the docs:

image

This PR takes the above suggestion of replacing wait() with communicate(), and making other related changes.

An alernative workaround, that also I found working, was:

import tempfile

def run_command(path, working_directory):
    with tempfile.NamedTemporaryFile(mode="w+") as tmp_out, tempfile.NamedTemporaryFile(mode="w+") as tmp_err:

        p = subprocess.Popen(path, shell=True, stdin=subprocess.PIPE,
                            stdout=tmp_out, stderr=tmp_err,
                            universal_newlines=True,
                            cwd=working_directory)
        result = p.wait()
        tmp_out.seek(0)
        tmp_err.seek(0)
        stdout = tmp_out.readlines()
    return result, stdout

I would prefer the workaround in the PR more suitable, than the above option.