bazel: Pseudoterminals don't work in the Linux sandbox

Description of the problem / feature request:

When I run a python script, which uses the ‘sh’ module, from bazel genrule, it failed with this:

INFO: Analysed target //src:foo_gen (8 packages loaded).
INFO: Found 1 target...
ERROR: /home/libin11/workspace/test/test/src/BUILD:1:1: Executing genrule //src:foo_gen failed (Exit 1)
Traceback (most recent call last):
  File "src/test.py", line 2, in <module>
    sh.touch("foo.bar")
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 1427, in __call__
    return RunningCommand(cmd, call_args, stdin, stdout, stderr)
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 767, in __init__
    self.call_args, pipe, process_assign_lock)
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 1784, in __init__
    self._stdout_read_fd, self._stdout_write_fd = pty.openpty()
  File "/usr/lib/python2.7/pty.py", line 29, in openpty
    master_fd, slave_name = _open_terminal()
  File "/usr/lib/python2.7/pty.py", line 70, in _open_terminal
    raise os.error, 'out of pty devices'
OSError: out of pty devices
Target //src:foo_gen failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 2.143s, Critical Path: 0.12s
INFO: 0 processes.
FAILED: Build did NOT complete successfully

Feature requests: what underlying problem are you trying to solve with this feature?

I want to integrate a thirdparty project to my own. The third party project is built with a python script, so I would like to build the project with bazel genrule.

Bugs: what’s the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Example file list:

.
├── src
│   ├── BUILD
│   └── test.py
└── WORKSPACE

WORKSPACE is empty, BUILD is:

genrule(
    name = "foo_gen",
    srcs = glob(["**/*"]),
    outs = ["foo.bar"],
    cmd = "python $(location test.py)",
)

test.py is:

import sh
sh.touch("foo.bar")

And run:

bazel build //src:foo_gen

What operating system are you running Bazel on?

Ubuntu 16.04

What’s the output of bazel info release?

release 0.14.1

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 19 (11 by maintainers)

Commits related to this issue

Most upvoted comments

An easier reproduction doesn’t need the sh module to be installed. Some test.py file:

import pty
pty.openpty()

and then:

.../path/to/install/base/linux-sandbox python test.py

is sufficient.

I think this should work. I don’t see why the sandbox should disallow pseudoterminals (if that’s what it’s doing). It might have something to do with access to /dev though. Would need some more investigation before saying that this is just a doc fix, in particular because I suspect this will behave differently between Mac and Linux.

Any updates around this?