jeff.hykin
jeff.hykin
DDeno
Created by jeff.hykin on 6/30/2024 in #help
`deno compile` offline [Solved]
- I've got a sandbox (the nix packaging system requires it) - I run deno compile a.js outside the sandbox. Works fine. - I copy $HOME/.cache/deno into the sandbox - I copy $TMP into the sandbox - I download denort-x86_64-unknown-linux-gnu.zip and copy it into the sandbox - (I don't know where to put it) - I run deno compile a.js in the sandbox (no internet permissions) and get: - error sending request for url (https://dl.deno.land/release/v1.44.4/denort-x86_64-unknown-linux-gnu.zip) Where can I put the denort.zip where deno will find it?
3 replies
DDeno
Created by jeff.hykin on 2/25/2024 in #help
deno_core manual tick/poll
(Learning the ropes of deno_core) Two related questions: - If I create a JsRuntime, and call poll_event_loop manually. Do I still fundamentally need tokio to be running? - I'd like to have a rust code execute in parallel/collaboration with a single embedded deno runtime. E.g. pure rust code in a secondary thread passes a task to the main thread deno runtime. Both the pure rust and deno run in parallel. The difficulty is then, the rust side, at some point, needs to grab a lock and pause the deno runtime. Meaning the deno tick loop also needs to be grabbing a lock on every tick (or grabbing a lock for a group of ticks for better throughput). After acquiring the lock, the pure rust side would then check the status of tasks in the deno runtime, give deno runtime more things to eval, then release the lock and let it start ticking away again. Aside from the natural difficultly of rust and threading, is this realistic? Or is there some tokio/inter-threading problems missing from my mental model
1 replies
DDeno
Created by jeff.hykin on 12/9/2023 in #help
Sync Child Stdin Read
I'd like to make a JS wrapper around the repl of another language. For example:
let a = otherLang`10`
let b = otherLang`{ c = 11; d = 12; }`;
console.log(b.c) // 11
let a = otherLang`10`
let b = otherLang`{ c = 11; d = 12; }`;
console.log(b.c) // 11
I can spawn a repl in a subprocess, keep it open and hook into the stdin/out/err of it. Then the idea would be to do something like the following:
otherLang`{ c = 11; d = 12; }`

// roughly becomes
child.stdin.write(`
print(json(listAttrNames(
{ c = 11; d = 12; }
)))
print(${endUuid})
`)
while (1) {
child.stdout.read() // until endUuid
}
otherLang`{ c = 11; d = 12; }`

// roughly becomes
child.stdin.write(`
print(json(listAttrNames(
{ c = 11; d = 12; }
)))
print(${endUuid})
`)
while (1) {
child.stdout.read() // until endUuid
}
The problem is something like that^ needs to run inside of a getter for console.log(b.a) to work. E.g. no async. I can do some incredibly hacky work, like funneling stdout to a file and then sync-reading (.seek()) the file over and over. But surely there's a better way. Relevant documentation on streams: https://deno.land/api@v1.38.5?s=ReadableStreamBYOBReader
5 replies
DDeno
Created by jeff.hykin on 8/14/2023 in #help
Deno Repl Programmatically
Python has a really nice not-well-known tool for creating a repl at any point in the code (kinda like a debugger but without any need for all the debugging setup). For example,
def somethin():
func = two_hour_long_computation_with_hard_to_serialze_output()
try:
a = untested_code_1(func)
b = untested_code_2(func)
c = untested_code_3(func)
except Exception as error:

#### important bit: creates a repl ####
import code; code.interact(local={**globals(),**locals()})
#### important bit ^ ####

save_results(a,b,c)
def somethin():
func = two_hour_long_computation_with_hard_to_serialze_output()
try:
a = untested_code_1(func)
b = untested_code_2(func)
c = untested_code_3(func)
except Exception as error:

#### important bit: creates a repl ####
import code; code.interact(local={**globals(),**locals()})
#### important bit ^ ####

save_results(a,b,c)
I then get a repl where I can poke around with the a, b, error vars, fix them and when I exit the repl it resumes execution (saving the output to disk so that I don't have to wait another 2 hours) Is there a way to do this in Deno? e.g. some unstable/hidden Deno.repl() I know a hacky solution could be made in userland via eval, but I wanted to check and see if there was an existing way
7 replies
DDeno
Created by jeff.hykin on 2/13/2023 in #help
Deno.run Strange Issue
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)
8 replies
DDeno
Created by jeff.hykin on 2/1/2023 in #help
Publishing Deno Module with Bin (Answered)
I know there's a way to include a bin/ when publishing a module and then perform some kind of deno install https://module-url because I've used it before. But now that I'm searching for it, "bin", "executable", and the like only turn up docs on deno compile. I remeber there was an example installing curl.ts (https://deno.land/std@0.168.0/examples/curl.ts) but I can't seem to find that example either. Could someone point me in the right direction?
2 replies
DDeno
Created by jeff.hykin on 11/5/2022 in #help
How to cancel or abort .pipeTo()?
I prefer not asking, but after I found (what I consider) an MDN easter egg, I realized this is probably not something I'm going to solve without help from runtime-implementers. https://user-images.githubusercontent.com/17692058/200146738-da3e8747-6c7f-4ec7-adb8-fbb8c8947d33.png The example is straightforward, call stream1.pipeTo(stream2) then, with full access to both stream1 and stream2 try to shutdown/cancel/close/abort/sabotage/nuke stream1, stream2 or even just the pipe itself (copy-paste example below). The big issue is that, because of the pipeTo the deno process never ends. I've tried absolutely everything I can think of, including inheriting from WritableStream, prototype pollution hacks, accessing probably-shouldnt-be-accessed-directly-symbol keys, etc and I've not got a hint of success
// dont use deno repl for this code, use deno eval instead, b/c the Deno.stdin access will freeze the whole repl
const [ stream1, newStdinReadable ] = Deno.stdin.readable.tee()
const stream2 = new WritableStream({}, new CountQueuingStrategy({ highWaterMark: 1 }))
stream1.pipeTo(
stream2,
{ preventClose: false, preventAbort: false, preventCancel: false,}
)
// stream1.stopPipingTo(stream2)
try { await stream1.cancel() } catch (error) { console.log(error) }
// ^ Cannot cancel a locked ReadableStream.
try { await stream1.abort() } catch (error) { console.log(error) }
// ^ TypeError: stream1.abort is not a function
try { await stream1.close() } catch (error) { console.log(error) }
// ^ TypeError: stream1.close is not a function
try { await stream2.cancel() } catch (error) { console.log(error) }
// ^ TypeError: stream2.cancel is not a function
try { await stream2.abort() } catch (error) { console.log(error) }
// ^ TypeError: The writable stream is locked, therefore cannot be aborted.
try { await stream2.close() } catch (error) { console.log(error) }
// ^ TypeError: The writable stream is locked, therefore cannot be closed.
// dont use deno repl for this code, use deno eval instead, b/c the Deno.stdin access will freeze the whole repl
const [ stream1, newStdinReadable ] = Deno.stdin.readable.tee()
const stream2 = new WritableStream({}, new CountQueuingStrategy({ highWaterMark: 1 }))
stream1.pipeTo(
stream2,
{ preventClose: false, preventAbort: false, preventCancel: false,}
)
// stream1.stopPipingTo(stream2)
try { await stream1.cancel() } catch (error) { console.log(error) }
// ^ Cannot cancel a locked ReadableStream.
try { await stream1.abort() } catch (error) { console.log(error) }
// ^ TypeError: stream1.abort is not a function
try { await stream1.close() } catch (error) { console.log(error) }
// ^ TypeError: stream1.close is not a function
try { await stream2.cancel() } catch (error) { console.log(error) }
// ^ TypeError: stream2.cancel is not a function
try { await stream2.abort() } catch (error) { console.log(error) }
// ^ TypeError: The writable stream is locked, therefore cannot be aborted.
try { await stream2.close() } catch (error) { console.log(error) }
// ^ TypeError: The writable stream is locked, therefore cannot be closed.
4 replies