Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Detaching sometimes throws ValueError: I/O operation on closed file. #1165

Closed
karthiknadig opened this issue Feb 21, 2019 · 2 comments
Closed
Assignees
Labels
Milestone

Comments

@karthiknadig
Copy link
Member

Environment data

  • PTVSD version: master
  • OS and version: linux
  • Python version (& distribution if applicable, e.g. Anaconda): 3.5
  • Using VS Code or Visual Studio: VSC

Actual behavior

I see this error on detach.

Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/ptvsd/_vendored/pydevd/pydevd.py", line 1905, in stoptrace
    debugger.exiting()
  File "/usr/local/lib/python3.5/dist-packages/ptvsd/_vendored/pydevd/pydevd.py", line 1590, in exiting
    sys.stdout.flush()
  File "/usr/local/lib/python3.5/dist-packages/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_io.py", line 37, in flush
    r.flush()
ValueError: I/O operation on closed file.

Expected behavior

Should not throw error. Should continue user process.

Steps to reproduce:

Launch the following script:

import multiprocessing
multiprocessing.set_start_method('spawn', True)
import concurrent.futures

FIBS = [28, 10]

def fib(n):
    print(n)
    if n < 2:
        return 1
    return fib(n - 1) + fib(n - 2)


def main():
    with concurrent.futures.ProcessPoolExecutor() as executor:
        executor.map(fib, FIBS)


if __name__ == '__main__':
    main()

Using the following command:
python3 -m ptvsd --host 0.0.0.0 --port 5678 --wait --multiprocess ./mymain.py

Attach to this from VSC, with breakpoint set on the print line.

        {
            "name": "Attach",
            "type": "python",
            "request": "attach",
            "port": 5678,
            "host": "localhost",
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "."
                }
            ],
            "debugStdLib": true,
        },
@qubitron qubitron added this to the Mar 2019.1 milestone Mar 6, 2019
@int19h
Copy link
Contributor

int19h commented Mar 12, 2019

On Windows, the repro steps trigger a different exception, when detaching from the root process:

Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "C:\Python\3.7-64\lib\concurrent\futures\process.py", line 101, in _python_exit
    thread_wakeup.wakeup()
  File "C:\Python\3.7-64\lib\concurrent\futures\process.py", line 89, in wakeup
    self._writer.send_bytes(b"")
  File "C:\Python\3.7-64\lib\multiprocessing\connection.py", line 183, in send_bytes
    self._check_closed()
  File "C:\Python\3.7-64\lib\multiprocessing\connection.py", line 136, in _check_closed
    raise OSError("handle is closed")
OSError: handle is closed

int19h added a commit to int19h/ptvsd that referenced this issue Mar 14, 2019
…ion on closed file

Gracefully handle failures when flushing potentially closed standard streams on exit.

Add more multiprocess logging, and fix sys.argv logging.
@int19h
Copy link
Contributor

int19h commented Mar 14, 2019

OSError is an unrelated issue, and happens because we kill child processes when detaching from parent. ProcessPoolExecutor expects them to still be there when running its cleanup code via atexit, and doesn't try to guard against the possibility of failure. Not sure what we can do here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants