Python flake8 intermittently shows no results - possible diagnosis

Skip to first unread message

Weeble Wilson

Oct 17, 2014, 11:44:19 AM10/17/14
I've been struggling to get flake8 to work consistently in syntastic. Sometimes errors are highlighted correctly, sometimes no errors are highlighted. For example, I might save my file several times in a row with no changes. Sometimes errors will be highlighted, most times they won't.

After some investigation, I believe there's a weird interaction between flake8, multiprocessing, and vim's "system" function at the root of this problem. Evidence:

1. Exporting PYTHONUNBUFFERED=1 before starting vim fixes all problems. Syntastic highlights errors correctly every time if it is set.

2. Manually invoking this ex command results in no output:
    :echo system('python3 -m flake8')

3. Manually invoking this ex command results in a list of error locations:
    :echo system('python3 -u -m flake8')

4. Manually invoking this at a shell always results in a list of error locations:
    python3 -m flake8

5. The same behaviour (output/no output) can be observed with this Python script:

    import multiprocessing

    q = multiprocessing.Queue()
    def sayhello():

    p = multiprocessing.Process(target=sayhello)
    p.daemon = True

This is my attempt to make a minimal reproduction of what flake8 does. I believe this gives no guarantee that the child process has flushed its output at the point when the parent process exits. I suspect that the "system" function does not wait for the output pipe to be closed, and stops waiting for output as soon as the parent process returns an exit code.

At this point, I don't know which program is broken. Is this a bug in flake8? It seems broken if its daemon processes never flush their output and are allowed to be killed by the parent process. But at the same time, I can't reproduce the failure to produce output outside of vim. If I run flake8 at the command-prompt, it always produces output, which suggests the daemon processes do manage to flush their output before they die, but perhaps not in time for vim? Or is this a bug in vim? Should it wait for EOF on the output pipe from the process created by the system call?

I'm running Ubuntu 14.04 (x86_64) in a Virtualbox VM on a Windows host. Virtualbox is configured to expose 2 CPUs to the VM. I have versions:

flake8: 2.2.4
cpython: 3.4.0
vim: 7.4
syntastic: 3.5.0

Has anyone else encountered this issue or looked into the problem?
Reply all
Reply to author
0 new messages