D
Deno

help

Deno.run Strange Issue

Jjeff.hykin2/13/2023
I use Deno.run + stdout/signals/etc a lot, but this behavior is beyond my current debugging abilities I have a command nix eval ... which works fine in a python subshell, and on the commandline. However, Deno.run with piped stdout makes it hang indefinitely. To be explicit, in this block: process.status().then(callback).catch(callback) the callback doesn't run until a .kill() is used (SIGHUP/SIGINT/SIGKILL). Tested on Deno 1.29.4 and Deno 1.22.0 for good measure. What is even more strange is trying to bypass the problem with hackery also fails. All of these round-about execution methods (translated to Deno.run) also hang indefinitely: - bash -c '[command]' - bash ./file_with_command.sh - bash -i ./file_with_command.sh In particular the bash -i method not only hangs, but also exclusively makes it so that ctrl+C, ctrl+D, and even ctrl+Z are ignored; I have to kill the deno process from another termial. Env: bash -c env prints out the EXACT same env vars for Deno/Python/CLI Cwd: deno/python/cli all have the same working directory Interactivity: running it with deno repl has been the same as deno run Piping: Manually closing the stdout pipe doesn't work/help. Removing stdout: 'piped', makes command not-hang (but defeats the point). Adding stderr: 'piped' still causes a hang. I don't even know what else could be possibly causing a difference (Deno & Python code attached as comments)
Jjeff.hykin2/13/2023
Here's the deno code (does need nix: https://nixos.org/download.html ):
const process = Deno.run({
"cmd": [
"nix",
"eval",
"-I", "nixpkgs=https://github.com/NixOS/nixpkgs/archive/aa0e8072a57e879073cee969a780e586dbe57997.tar.gz",
"--impure",
"--expr", "(builtins.attrNames (import <nixpkgs> {}))",
],
"stdout": "piped"
})
console.debug(`process is:`,process)
console.debug(`await process.status() is:`,await process.status())
const process = Deno.run({
"cmd": [
"nix",
"eval",
"-I", "nixpkgs=https://github.com/NixOS/nixpkgs/archive/aa0e8072a57e879073cee969a780e586dbe57997.tar.gz",
"--impure",
"--expr", "(builtins.attrNames (import <nixpkgs> {}))",
],
"stdout": "piped"
})
console.debug(`process is:`,process)
console.debug(`await process.status() is:`,await process.status())
And here is the python for comparison
def run(*cmd, timeout_sec=None):
from subprocess import Popen, PIPE
proc = Popen(cmd, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
return stdout.decode('utf-8')[0:-1], stderr.decode('utf-8')[0:-1]

print(
run(
"nix",
"eval",
"-I", f'nixpkgs=https://github.com/NixOS/nixpkgs/archive/aa0e8072a57e879073cee969a780e586dbe57997.tar.gz',
'--impure',
'--expr', '(builtins.attrNames (import <nixpkgs> {}))'
)
)
def run(*cmd, timeout_sec=None):
from subprocess import Popen, PIPE
proc = Popen(cmd, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
return stdout.decode('utf-8')[0:-1], stderr.decode('utf-8')[0:-1]

print(
run(
"nix",
"eval",
"-I", f'nixpkgs=https://github.com/NixOS/nixpkgs/archive/aa0e8072a57e879073cee969a780e586dbe57997.tar.gz',
'--impure',
'--expr', '(builtins.attrNames (import <nixpkgs> {}))'
)
)
And for good measure here is also Ruby code, which also doesn't hang
puts `nix eval \
-I nixpkgs=https://github.com/NixOS/nixpkgs/archive/aa0e8072a57e879073cee969a780e586dbe57997.tar.gz \
--impure \
--expr '(builtins.attrNames (import <nixpkgs> {}))'`
puts `nix eval \
-I nixpkgs=https://github.com/NixOS/nixpkgs/archive/aa0e8072a57e879073cee969a780e586dbe57997.tar.gz \
--impure \
--expr '(builtins.attrNames (import <nixpkgs> {}))'`
IioB2/13/2023
I haven't had a chance to look into why this might be hanging, but I will point out that Deno.run is being deprecated in favor of Deno.Command which has an objectively clearer api. I will look into this when I get the chance
AAapoAlas2/13/2023
Deno.run does have some hanging issue as well. If memory serves then one way around it is to await Promise.all() all the three outputs of the run, not only status but stdout and stderr as well.
Jjeff.hykin2/13/2023
I was looking into that but are there docs for Deno.Command? I expanded every section on https://deno.land/api@v1.30.3 and ctrl+f still returns nothing It also doesn't seem to exist on 1.29.4
Jjeff.hykin2/13/2023
wow... this actually works/doesnt hang. Thanks @aapoalas
var process = Deno.run({
"cmd": [
"nix",
"eval",
"-I", "nixpkgs=https://github.com/NixOS/nixpkgs/archive/aa0e8072a57e879073cee969a780e586dbe57997.tar.gz",
"--impure",
"--expr", "(builtins.attrNames (import <nixpkgs> {}))",
],
"stdout": "piped"
})

Promise.all([
process.output(),
]).then(_=>console.log("outputs finished"))
await process.status()
var process = Deno.run({
"cmd": [
"nix",
"eval",
"-I", "nixpkgs=https://github.com/NixOS/nixpkgs/archive/aa0e8072a57e879073cee969a780e586dbe57997.tar.gz",
"--impure",
"--expr", "(builtins.attrNames (import <nixpkgs> {}))",
],
"stdout": "piped"
})

Promise.all([
process.output(),
]).then(_=>console.log("outputs finished"))
await process.status()
AAapoAlas2/13/2023
It's probably still under the "unstable" checkbox. IIRC the PR stabilising it has only just been merged or is about to be.
IioB2/13/2023
It is going to be part of v1.31.0 iirc

Looking for more? Join the community!

Recommended Posts
Properly continuously read data from a ReaderWhat's the proper way to continuously read from a `Deno.Reader`? I'm trying to parse incoming HTTP2npm:redis – everything returns `string`?Every command I try to use from `npm:redis` seems to have inferred return type `string`. Look at theMy magic middlewares typeIf anyone wants a typescript challange here is one: I am trying to create a tuple type which containRead one byte at a time from ReadableStreamWhat would be the most obvious way to read a single byte from a ReadableStream at a time?My deno.lock file exceeds 4000 lines of JSON nowIs this common for application projects? Is there any nice way to clean it up?importing packages breaks typesIm importing `Receiver` from https://deno.land/x/upstash_qstash@v0.3.2. but as soon as i import thisBug report: deno.land website returns a 500 error for JS filesOn https://deno.land, I noticed that the Node vs Deno comparison didn't seem to do anything. From Deno stopps at file.read()I am currently working on a way to communicate with a COM device. I can successfully open and read f[Resolved][Fresh] How to load data asynchronously after rendering a page ?Hi ! I was wondering if someone could help me understand the paradigm to load data asynchronously afSupabase Auth UI in FreshI'm building a simple web. I'd like to use Supabase's Auth UI, namely the `Auth` component, for handAny tool that will complie my TS code to JS?I have coded a website in typescript using Deno, but I want to convert it to JS code. I know the DenHow to get remote IP address when using Deno.serve?I'm using connInfo when using Deno from STD but the native http server doesn't seem to have such intTwo questions on documentationRTFM in 3... 2... 🙂 Question 1: How do i hide documentation for specific exports, i do not want Is there any simple way to keep track of the heap/stack usage of a running Deno application?I have made a Deno application and I'm curious to know if there's heap/stack issues that I should fiusing data from one deno bench in anotheris there any good way to re-use the results generated in one deno bench in another one? example: `docker compose up of Oak server throws: SyntaxError: Duplicate export of 'type'I am just learning how to use Docker, and am trying to put up a container of an Oak server. When run