Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: explain process.stdout in worker_threads #31292

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/api/tty.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ The `tty.isatty()` method returns `true` if the given `fd` is associated with
a TTY and `false` if it is not, including whenever `fd` is not a non-negative
integer.

Within `worker_threads`, this API will return `false` for process.stdout.
This is because the `process.stdout` of the worker is a pipe into the parent,
not actually a TTY.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not accurate:

> void new Worker(`console.log('isatty(1)', require('tty').isatty(1))`, {eval:true})
undefined
> isatty(1) true

tty.isatty() is generally not concerned with what thread it’s being called on, as fds are a process-wide resource.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@addaleax , I am describing fd 1, instead process.stdout.fd

void new Worker(`console.log('isatty(process.stdout.fd)', require('tty').isatty(process.stdout.fd))`, {eval:true})
undefined
satty(process.stdout.fd) false

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit: I am describing fd 1 -> I am NOT describing fd 1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process.stdout.fd is undefined in a worker thread. (Should it be?)

> void new Worker('console.log("fd:", process.stdout.fd)', {eval: true})
undefined
> fd: undefined


[`process.stderr`]: process.html#process_process_stderr
[`process.stdin`]: process.html#process_process_stdin
[`process.stdout`]: process.html#process_process_stdout
Expand Down