Better HN
topnewbestaskshowjobs
Log inSign up

devxpy

515 karma · joined Dec 27, 2017 (8y ago) · 421 submissions

https://github.com/devxpy
Submissions

comment 6y ago · link · parent

Please, some data to back this claim?

comment 6y ago · link · parent

Whats even more insane is how bad their documentation is.

Especially with AWS I feel like I get ripped off everytime I use any of their services, because there's always some magic, undocumented buttons I need to press in their godforsaken gui to make it work.

comment 6y ago · link · parent

Nathaniel has done a great job of drawing parallels between go and goto.

I've been stung, time and again by asyncio.create_task() swallowing exceptions[1], and functions not telling callers about background tasks[2].

For others looking to NOT rewrite all their code using a 3rd party event loop, here's a simple reproduction of nursery's behaviour in raw asyncio -

Hopefully, this will help lift the curse of asyncio :)

[EDIT] A library is also available - https://github.com/Tygs/ayo (with amazing operator overload)

  async def main():
      async with Nursery() as ny:
          ny.start_soon(a_1(), a_2(), ..., a_n())
          ny.start_soon(b_1(), b_2(), ..., b_n())
          .
          .
          .
          ny.start_soon(x_1(), x_2(), ..., x_n())


  class Nursery:
      def __init__(self):
          self.tasks = set()
  
      def start_soon(self, *coros: typing.Coroutine):
          for coro in coros:
              self.tasks.add(asyncio.create_task(coro))
  
      async def __aenter__(self):
          return self
  
      async def __aexit__(self, *args):
          try:
              while self.tasks:
                  tasks = self.tasks
                  self.tasks = set()
  
                  done, pending = await asyncio.wait(
                      tasks, return_when=asyncio.FIRST_COMPLETED
                  )
  
                  try:
                      for task in done:
                          await task
                  finally:
                      self.tasks |= pending
          finally:
              for task in self.tasks:
                  task.cancel()
[1] https://stackoverflow.com/questions/60287285/starlette-async...

[2] https://github.com/encode/starlette/issues/947

comment 6y ago · link · parent

Just an aside from the argument here, I think almost no python API actually follows the zen of python. It's certainly a nice idea, just incredibly hard to actually live upto in the real world.

comment 6y ago · link · parent

Can't you just use the ProcessPoolExecutor[1] for CPU heavy stuff? AFAIK, GIL isn't much of an issue with I/O tasks.

[1] https://docs.python.org/3.8/library/concurrent.futures.html#...

comment 6y ago · link · parent

Why do you say that?

I believe concurrent.futures is meant as a way for asyncio to spawn threads or processes -- which lets you essentially call sync code from async and not have it block the event loop.

From the docs[1] -

The concurrent.futures module provides a high-level interface for asynchronously executing callables.

The asynchronous execution can be performed with threads, using ThreadPoolExecutor, or separate processes, using ProcessPoolExecutor. Both implement the same interface, which is defined by the abstract Executor class.

[1] https://docs.python.org/3.8/library/concurrent.futures.html

comment 6y ago · link · parent

Why would the Gil apply to asyncio, which is strictly single threaded?

comment 6y ago · link · parent

> Many popular languages today predate modern asynchronous computing. This makes async-as-default impossible because it's an afterthought

Here's a rough sketch of how this can be achieved for a language that already has event loops -

Transpile the following -

    void main() {
        Future<int> xFuture = async doSomething()
        int x = doSomething()
         
        assert(await xFuture == x);
    }
Into -

    Future<void> main() async {
        Future<int> xFuture = (() async => await doSomething())();
        int x = await doSomething();
      
        assert(await xFuture == x);
    }
Now people can keep using a pre-existing `doSomething()` (that's either async or sync) and its compatible with our new caller based async statement.

BTW that transpiler output is runnable dart code actually works.

I know this has tons of edge cases that this simple example doesn't capture, but it's definitely "possible".

comment 6y ago · link · parent

How do you plan on making this concurrent? Generators can defer computation for later, but that doesn't magically make them async.

comment 6y ago · link · parent

I've been thinking why exactly async-await was chosen at the function level, and not the caller level.

I mean for languages that have event loops at their core, why isn't every function `async` by default? Let the caller decide how it wants to use the function.

`async` functions don't wait for a result of a `Future` unless `await` is used.

Instead of putting all that effort into putting `await` everywhere, why not invert that logic and make them `await` by default, and instead have the async-await syntax used by callers?

Like if one to were to write a transpiler to do this in dart, it might compile the following -

    void main() {
        Future<int> xFuture = async doSomething()
        int x = doSomething()
         
        assert(await xFuture == x);
    }

    int doSomething {
        ...
    }
into -

    Future<void> main() async {
        Future<int> xFuture = doSomething()
        int x = await doSomething()

        assert(await xFuture == x);
    }

    Future<int> doSomething async {
        ...
    }

This might be stupid, but my solution to the "what color is your function problem" is to make every function async.

I looks an awful lot like what go does with its `go` syntax, but because you have an event loop with Future and Async Streams, you don't need to worry about dealing with CSP.

comment 6y ago · link · parent

In a similar "Curly" style, Victor Mono - https://rubjo.github.io/victor-mono/

comment 6y ago · link · parent

Yes, something like that.

Like here's David's "Build Your Own Async" [1], which I prefer over Philip's (still extremely good) "What the heck is the event loop anyway?" [2].

It's one thing to tell how something works, but to successfully show what the hell its actually doing under the covers, just conveys much more information.

[1] https://www.youtube.com/watch?v=Y4Gt3Xjd7G8 [2] https://www.youtube.com/watch?v=8aGhZQkoFbQ

comment 6y ago · link · parent

While this is interesting, it doesn't really show how containers actually work, only lists the specific syscall flags to tell Linux create one.

A similar snippet[1] exists for go, and it doesn't do anything particularly special either.

I don't know, maybe David beazley has altered my sense of what "from scratch" means.

[1] https://gist.github.com/lizrice/a5ef4d175fd0cd3491c7e8d71682...

comment 6y ago · link · parent

I think flutter puts a nail in the coffin with its semi-declarative syntax.

While you're technically programming using an imperative language, they've somehow managed to make the syntax close enough to a declarative one that it isn't just a soup of bare object surgery (like tkinter or java swing).

They also, really went the extra mile to NOT have to do tree diffing[1], by making Widgets immutable, while still having a "detached" State associated with them.

And this is eerily close to the JSON-is-HTML syntax the author is proposing. A replication of flutter's strategy in pure JS is defininitely worth exploring.

[1] https://flutter.dev/docs/resources/inside-flutter#linear-rec...

comment 6y ago · link · parent

I don't think mac has any hidpi support at all. They just decrease the resolution.

Last time I used it, KDE had _proper_ fractional scaling and rendered fonts at full resolution compared to mac, which by default runs at lower than native resolution of my retina MacBook pro.

comment 6y ago · link · parent

By hiring the Silicon Ronin, ofcourse.

https://en.m.wikipedia.org/wiki/Jim_Keller_(engineer)

comment 6y ago · link · parent

Phew. So much for the app store not deterministically notifying the server deployment infrastructure that the app has been published?

138.

Ask HN: How to sync server and app deploys?

1 points · by devxpy · 6y ago · 2 comments

comment 6y ago · link · parent

That takes care of lost information, but how do you reliabiliy filter out signal from noise? Can a simple FIR filter work in this situation?

comment 6y ago · link · parent

So it's more about the beuraucracy than the tech?

comment 6y ago · link · parent

That's actually a lot of money in an Indian context. Although outsourcing to another country might raise other kind of political problems.

comment 6y ago · link · parent

Exactly. If it were not for the OS, the hardware seems to be a lot more capable than casual entertainment. These use cases simply don't push the hardware to its limits.

comment 6y ago · link · parent

> companies can't protect us from a government we have put into power.

But.. the electoral college.

comment 6y ago · link · parent

I wonder if this could be improved with SQL

comment 6y ago · link · parent

Starlette is very nice.

starlette.io/

comment 7y ago · link · parent

That's because for some reason, people treat computer science and programming as the same thing. IMO they're completely separate things, at least in practice.

comment 7y ago · link · parent

Wow, wasn't expecting such a well constructed counter argument.

comment 7y ago · link · parent

With superb open source, cross platform libraries like pdfium available to the public, why won't I just do this on the client?

149.

Jancy – scripting language with C ABI/source compatibility(github.com ↗)

1 points · by devxpy · 7y ago · discuss

comment 7y ago · link · parent

Are you talking about this [1]?

Perhaps it's possible to just use PL/Python[2] to write a custom stored prodecure?

[1] https://docs.hasura.io/1.0/graphql/manual/schema/default-val...

[2] https://www.postgresql.org/docs/10/plpython.html

1
456
15