jwilk / didjvu

DjVu encoder with foreground/background separation
https://jwilk.net/software/didjvu
GNU General Public License v2.0
10 stars 8 forks source link

didjvu bundle --pages-per-dict=N: OSError: [Errno 24] Too many open files #14

Open jwilk opened 4 years ago

jwilk commented 4 years ago

Apparently the --pages-per-dict option causes file descriptor leak:

$ didjvu bundle --pages-per-dict=10 *.tiff -o tmp.djvu
⋮
0255.tiff:
- reading image
- converting to DjVu
Traceback (most recent call last):
  File "/home/jwilk/.local/bin/didjvu", line 25, in <module>
    didjvu.main()
  File "/home/jwilk/.local/share/didjvu/lib/didjvu.py", line 203, in __init__
    parser.parse_args(actions=self)
  File "/home/jwilk/.local/share/didjvu/lib/cli.py", line 348, in parse_args
    return action(o)
  File "/home/jwilk/.local/share/didjvu/lib/didjvu.py", line 355, in bundle
    self.bundle_complex(o)
  File "/home/jwilk/.local/share/didjvu/lib/didjvu.py", line 438, in bundle_complex
    itertools.repeat(pixels)
  File "/home/jwilk/.local/share/didjvu/lib/didjvu.py", line 68, in parallel_for
    f(o, *args)
  File "/home/jwilk/.local/share/didjvu/lib/didjvu.py", line 410, in _bundle_complex_page
    page.djvu = image_to_djvu(width, height, image, mask, options=o)
  File "/home/jwilk/.local/share/didjvu/lib/didjvu.py", line 161, in image_to_djvu
    sjbz = djvu.bitonal_to_djvu(gamera.to_pil_1bpp(mask), loss_level=loss_level)
  File "/home/jwilk/.local/share/didjvu/lib/djvu_support.py", line 81, in bitonal_to_djvu
    return utils.Proxy(djvu_file, ipc.Subprocess(args).wait, [pbm_file])
  File "/home/jwilk/.local/share/didjvu/lib/ipc.py", line 107, in __init__
    subprocess.Popen.__init__(self, *args, **kwargs)
  File "/usr/lib/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 928, in _execute_child
    errpipe_read, errpipe_write = self.pipe_cloexec()
  File "/usr/lib/python2.7/subprocess.py", line 865, in pipe_cloexec
    r, w = os.pipe()
OSError: [Errno 24] Too many open files: 'cjb2'
jwilk commented 4 years ago

At least on Debian systems, soft limit for the number of open files is quite tight, but the hard limit is not:

$ ulimit -S -n
1024

$ ulimit -H -n
1048576

So as a work-around you could just raise the soft limit:

$ ulimit -S -n 1048576