ipython / ipython/ipython

fd leak after embed

Open
#11,753 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
16.8k
Forks
4.5k
Avg merge
1d 2h
Merged PRs (30d)
6

Description

It seems like `IPython.embed` is not correctly restoring file descriptors after it exits.

Example script:
```python
import os, subprocess

def print_fd(pid=None):
if pid is None:
pid = os.getpid()
print('\npid = {}'.format(pid))
subprocess.call('ls -la /proc/{}/fd'.format(pid), shell=True)
print()

def main():
print('\nBefore')
print_fd()
from IPython import embed; embed()
print('\nAfter')
print_fd()

if __name__ == '__main__':
main()
```

Output
```console
$ python3 lala.py

Before

pid = 42928
total 0
dr-x------ 2 me me 0 May 27 22:09 .
dr-xr-xr-x 9 me me 0 May 27 22:09 ..
lrwx------ 1 me me 64 May 27 22:09 0 -> /dev/pts/2
lrwx------ 1 me me 64 May 27 22:09 1 -> /dev/pts/2
lrwx------ 1 me me 64 May 27 22:09 2 -> /dev/pts/2

Python 3.6.4 (default, Jan 24 2019, 05:49:39)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.5.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]:
Do you really want to exit ([y]/n)?

After

pid = 42928
total 0
dr-x------ 2 me me 0 May 27 22:09 .
dr-xr-xr-x 9 me me 0 May 27 22:09 ..
lrwx------ 1 me me 64 May 27 22:09 0 -> /dev/pts/2
lrwx------ 1 me me 64 May 27 22:09 1 -> /dev/pts/2
l-wx------ 1 me me 64 May 27 22:09 10 -> pipe:[2804779437]
lrwx------ 1 me me 64 May 27 22:09 2 -> /dev/pts/2
l-wx------ 1 me me 64 May 27 22:09 3 -> /dev/null
lrwx------ 1 me me 64 May 27 22:09 4 -> /home/me/.ipython/profile_default/history.sqlite
lrwx------ 1 me me 64 May 27 22:09 5 -> /home/me/.ipython/profile_default/history.sqlite
lrwx------ 1 me me 64 May 27 22:09 6 -> anon_inode:[eventpoll]
lr-x------ 1 me me 64 May 27 22:09 7 -> pipe:[2804779436]
l-wx------ 1 me me 64 May 27 22:09 8 -> pipe:[2804779436]
lr-x------ 1 me me 64 May 27 22:09 9 -> pipe:[2804779437]
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.