You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Spawn a worker thread that is meant to interact with the CLI. The spawned worker's process.stdout will not have a columns property nor getWindowSize.
How often does it reproduce? Is there a required condition?
100%
What is the expected behavior?
I would expect to have access to the dimensions of the parent stdout within the worker thread.
What do you see instead?
Within the worker thread, process.stdout.columns is undefined, as is getWindowSize
Additional information
When spawning a worker thread that is responsible for interacting with the CLI, tools will rely upon the dimensions of stdout for calculating bounds. Currently I'm working around this by passing the existing dimensions as an environment variable, and then patching them onto the worker's stdout on load.
The text was updated successfully, but these errors were encountered:
arciisine
changed the title
Worker Threads do not preserve process.stdout.columns or have access to process.stdout.getWindowSize
Worker Threads do not have access to process.stdout.columns or process.stdout.getWindowSizeMay 31, 2020
arciisine
changed the title
Worker Threads do not have access to process.stdout.columns or process.stdout.getWindowSize
Worker Threads do not have access to process.stdout.columns or process.stdout.getWindowSize
May 31, 2020
I would consider this expected behavior. Worker threads don’t spawn with the same stdio streams as parent threads, but instead they pass the data between themselves and the main thread, similar to a pipe when spawning child processes.
Partially, this is because of a restriction in libuv that multiple threads can’t share access to the same file descriptor.
When spawning a worker thread that is responsible for interacting with the CLI
Worker threads are designed to offload CPU-intensive tasks off the main thread, and not really for more than that, at least currently. It sounds like you’re doing something that might better not be implemented as a worker thread?
I concur this isn't a great fit. I would honestly rather fork, but given that forking in node is just spawning a new process, I was trying to avoid the extra overhead. I would say though, that the flags for redirecting stdout from the worker to the parent's stdout, have a gap due to this issue.
If the desire is for proper formatting, I'm assuming that the child worker should never be outputting directly the process' stdout. Given this limitation and the limitations listed above, it seems like stdio from the child to the parent should generally be discouraged, and used in only the most trivial cases.
Thanks for the report. I think this is in broad strokes a duplicate of #26946. #26946 (comment) in particular applies and notes have been added to the documentation since.
I'll go ahead and close this out but let me know if there's still anything actionable on our side.
Node v14.2
Linux
Ubuntu 20.04
What steps will reproduce the bug?
Spawn a worker thread that is meant to interact with the CLI. The spawned worker's
process.stdout
will not have acolumns
property norgetWindowSize
.How often does it reproduce? Is there a required condition?
100%
What is the expected behavior?
I would expect to have access to the dimensions of the parent
stdout
within the worker thread.What do you see instead?
Within the worker thread,
process.stdout.columns
is undefined, as isgetWindowSize
Additional information
When spawning a worker thread that is responsible for interacting with the CLI, tools will rely upon the dimensions of stdout for calculating bounds. Currently I'm working around this by passing the existing dimensions as an environment variable, and then patching them onto the worker's
stdout
on load.The text was updated successfully, but these errors were encountered: