Better HN
topnewbestaskshowjobs
Log inSign up

BiteCode_dev

24,628 karma · joined Oct 21, 2019 (7y ago) · 5,512 submissions

I write to save you time and effort when dealing with Python:

https://www.bitecode.dev/

Email: contact at bitecode.dev

Submissions

comment 5y ago · link · parent

Oh, you meant like, why don't Python didn't reimplement the whole interpreter around concurrency instead of using the tools it already had to find solutions to problems?

Well, that question is as old as engineering itself, and it's always a matter of resources, cost, history and knowledge.

comment 5y ago · link · parent

You can await at the top level of a module since node v14.8.

It has been proposed to Python: https://groups.google.com/g/python-ideas/c/PN1_j7Md4j0/m/0xy...

But I have no more info about it.

comment 5y ago · link · parent

Anyio is probably a best bet to use TaskGroup IMO. You can use the trio backend if you want, after all.

But it's asyncio compatible, which makes it more future proof.

comment 5y ago · link · parent

It's a technical thread, not a political one. If you were so sure of your argument, you wouldn't use a throwaway.

Besides, it's weird, like saying we should not have int, float and complex, there should be one way to do it.

Just because those are 3 numbers doesn't mean they don't have each their own specific benefit.

comment 5y ago · link · parent

Oh, top level await... I missed that.

Not sure it will get there, but it would be nice. I think putting a top level "await" is explicit enough for stating you want an event loop anyway.

Now, with TaskGroup in 3.11, things are going to get pretty nice, espacially if this top level await plays out, provided they include async for and async with in the mix.

Now, if they could just make so that coroutines are automatically schedules to the nearest task group, we would almost have something usable.

comment 5y ago · link · parent

GOTO cosplaying should go away with structured concurrency (via TaskGroup) being adopted in 3.11, as pioneered by Trio.

Check out anyio if you want to use them now.

comment 5y ago · link · parent

While the design of Curio is quite interesting, it's may not be a good choice, not for technical reasons, but for logistical reasons: the chances it gets a wide adoption are slim to None.

And since we are stuck with colored functions in python, the choice of stack matters very much.

Now, if you want easier concurrency, and a solution to a lot of concurrency problems that curio solves, while still being compatible with asyncio, use anyio:

https://anyio.readthedocs.io/en/stable/

It's a layer that works on top of asyncio, so it's compatible with all of it. But it features the nursery concept from Trio, which makes async programming so much simpler and safer.

comment 5y ago · link · parent

No, it's just useful. They are techs with different trade off, and life is full of opportunities.

comment 5y ago · link · parent

It would not be pointless at all, because while one thread may lock on CPU, context switching will let another one deal with IO. This can let you smooth out the progress of each part of your program, and can be useful for workload when you don't want anything to block for too long.

comment 5y ago · link · parent

I used them both extensively, and here are the main reasons I can think of:

- The event loop in JS is invisible and implicit. V8 proved it can be done without paying a cost for it, and in fact most real life python projects are using uvloop because it's faster than asyncio default loop. JS dev don't think of the loop at all, because it's always been there. They don't have to chose a loop, or thinking about its lifecycle or scheduling. The API doesn't show the loop at all.

- Asynchronous functions in JS are scheduled automatically. On python, calling a coroutine function does...nothing. You have to either await it, or pass it to something like asyncio.create_task(). The later is not only verbose, it's not intuitive.

- Async JS functions can be called from sync functions transparently. It just returns a Promise after all, and you can use good old callbacks. Instantiating a Python coroutine does... nothing as we said. You need to schedule it AND await it. If you don't, it may or may not be executed. Which is why asyncio.gather() and co are to be used in python. Most people don't know that, and even if you know, it's verbose, and you can forget. All that, again, because using the event loop must be explicit. That's one thing TaskGroup from trio will help with in the next Python versions...

- the early asyncio API sucked. The new one is ok, asyncio.run() and create_task() with implicit loop is a huge improvement. But you better use 3.7 at least. And you have to think about all the options for awaiting: https://stackoverflow.com/questions/42231161/asyncio-gather-...

- asyncio tutorials and docs are not great, people have no idea how to use it. Since it's more complex, it compounds.

E.G, if you use await:

With node v14.8+:

    await async_func(params)
With python 3.7+:

    import asyncio 

    async def main():
        # no top level await, it must happen in a loop
        await async_func(params) 

    asyncio.run(main) # explicit loop, but easy one thanks to 3.7
E.G, deep inside functions calls, but no await:

With node:

    ...
    async_func(params)

With python 3.7+:

    ...
    # async_func(params) alone would do nothing
    res = asyncio.create_task(async_func(params))

    ...

    # you MAY get away with not using gather() or wait()
    # but you also may get "coroutine is never awaited"
    # RuntimeWarning: coroutine 'async_func' was never awaited
    asyncio.gather(res)
Of course, you could use "run_until_complete()", but then you would be blocking. Which is just not possible in JS, there is one way to do it, and it's always non blocking and easy. Ironic, isn't it? Beside, which Python dev knows all this? I'm guessing most readers of this post will have heard of it for the first time.

Python is my favorite language, and I can live with the explicit loop, but explicit scheduling is ridiculous. Just run the damn coroutine, I'm not instantiating it for the beauty of it. If I want a lazy construct, I can always make a factory.

Now, thanks to the trio nursery concept, we will get TaskGroup in the next release (also you can already use them with anyio):

    async with asyncio.TaskGroup() as tg:
        tg.start_soon(async_func, params)
Which, while still verbose, is way better:

- no gather or wait. Schedule it, it will run or be cleaned up.

- no need to chose an awaiting strat, or learn about a 1000 things. This works for every cases. Wanna use it in a sync call ? Pass the tg reference in it.

- lifecycle is cleanly scoped, a real problem with a lot of async code (including in JS, where it doesn't have a clean solution)

comment 5y ago · link · parent

Is that still maintained ? It was an experiment in 16.04 right?

comment 5y ago · link · parent

asyncio is not a competition to threads, it's complementary.

In fact, it's a perfectly viable strat in python to have several processes, each having several threads, each having an event loop.

And it will still be so, once this comes out. You will certainly use threads more, and processes less, but replacing 1000000 coroutines by 1000000 system threads is not necessarily the right strategy for your task. See nginx vs apache.

comment 5y ago · link · parent

Probably nice if you haven't read the books, because the direction is spotless.

But if you are a fan of the original story, it's a spit in the face of a masterpiece.

The title, names and arcs are basically used for branding.

It was predictable, the Foundation cycle is mostly dialogs spanned over hundreds of years. Little details is given to action, and characters, which are superficially developed and serve mostly the purpose of a vehicle for history, die of old age every few chapters or so.

Very hard to adapt, and pretty much impossible to make money outside of the show, with the face of your actors, by selling toys or pretty symbols. Also, good luck keeping hooked the general public. There is no focus on sexuality, little humor, hardly anyone relatable, they talk a lot then goodbye.

So they made it a block buster. It sure can work, but it's not Foundation.

comment 5y ago · link · parent

Oh boy, it's not just unentertaining, but a grotesque farce of what you get when you want to check all the bingo boxes for making something bankable, and in doing so, completely destroy the original content.

In the first minutes it's already game over: they try to get you interested in the human characters in a book where the main protagonist is an entire galaxy over centuries. All named persons are going to die every 3 chapters, I get that you can't get ROI on your expensive hot actors faces, but that makes no sense for the material you work with!

comment 5y ago · link · parent

All those distros have different default settings.

E.G: full disk encryption is enabled by default when you install it, which is the opposite of most Ubuntu based distros.

comment 5y ago · link · parent

I tried to install the pop shell, but it worked out badly. Those distro are not made to just have the DE installed after the installation of Ubuntu. Something always breaks.

You have to install from the official .iso

comment 5y ago · link · parent

Yeah, I've met those kind of comments for 15 years.

There is always somebody to say that in those kind of threads. Same as Vi is easy, try Manjaro, Nix, this latest implementation of LISP, that NoSQL db, this DSL, etc.

I used to give them the benefit of the doubt, spend some time testing the alternative the person talked about, came out disappointed, and wasted time.

Now I just trust numbers. When 100 people like you will tell me the same for 3 years, I will try.

Before that, I'll stay on what I know works.

comment 5y ago · link · parent

I tried so many distros. None of them fit the bill for a pro laptop.

I don't want to move out of ubuntu based distros, they get too many things right.

I'd rather try Elementary, Pop OS, Xubuntu, etc.

comment 5y ago · link · parent

I've been fighting to keep Unity as long as I could, but it's now breaking too often so I accepted my gnome shell fate. It requires 10 plugins, one app, and manually crafted .desktop files to be usable, but ok, it's free software, I'll adapt.

I understand the rational to also push for wayland first now, but it breaks my workflow for things like autokey. We do need to move from X11, but once again, something I will have to work with.

And now Firefox is a snap, which is slow, has permissions problems all around (guaranteed the sandbox will break some addons), takes a lot of space, etc. Again, I get it, it's a perfect candidate to push the tech, and they need to solve user facing apps distribution problem with linux.

I like Ubuntu a lot. I donate to it. I don't want to migrate to Manjaro or something else. Ubuntu is the sweet spot for things working out of the box.

But with 21.010, I really feel like at least moving to Elementary or PopOS right now. Tried them, the first one can't install (EFI partition is too small), the second breaks on my machine.

I don't like KDE, so I guess, next is Xubuntu? Something else?

comment 5y ago · link · parent

It works out of the box for most hardware, install proprietary things easily, including drivers and codecs, and have more up to date softwares. It also have lots of usability tweaks.

You can, have all that with debian, but then you have to do the work.

I don't want to do the work if canonical can do it for me.

comment 5y ago · link · parent

In their mind it makes sense: firefox is a user facing app that is frequently updated and requires a lot of dependencies. Perfect candidate for a snap.

But yeah, up to now, snaps really sucked, and flatpak is winning.

comment 5y ago · link · parent

The idea is that they won't tell themself, "I'm going to use the indian defense".

Just like I won't tell myself "I'm going to apply the strategy pattern here".

We just see the situation, and if it calls from a solution from the banks of solutions we have encountered in the past, we see if it fits, we try to apply it if it does (tailoring may be necessary).

Then the commentator later may say "oh, he decided to use Y". But that's for the benefits of the people watching.

comment 5y ago · link · parent

Well, in this day and age of bazooka DMCA take down, it's refreshing to see a game author happy about his game being gutted, and put online to play.

comment 5y ago · link · parent

- "Sir, I'm calling you because I found your card, I called your bank, and they gave me your number. They told me you should report the card as lost in case it's been used fraudulently with the phone number that is written at the back of the card"

- "Can you send me back the card?"

- "I'm in a train, I won't be able to do that for a while. You should really call"

- "But I don't have the number"

- "I can read it to you"

Pwn

comment 5y ago · link · parent

Nah, design patterns are mostly communication tools.

When you name something "factory", when some doc mentions "dependency injection", when you import a "register", when you talk with a colleague about a "decodator", if you know the name, you already know what it does, and what the API will probably look like.

I say probably, because we don't have a format definition of all design patterns, nor are they all recognized as such. For for the ones that are and we do, we don't all agree. Not to mention you must adapt them to problems and languages.

So sure, when you code and you encounter a problem, you may use a design pattern. But you don't explicitly do so. Just like a chess master doesn't chose a move by thinking "I'm going to use x", they just decide on it, and also adapt it to the situation.

I never think about design patterns when I code, only when I name the code, I write the doc, and talk about it. When I communicate.

If you read a book about design patterns, they will make no sense to you. You will probably misuse them. But if you look at real life source codes from other devs, or yours again and again, you realize some problems come back often, and a lot of people use similar solutions. Then you look it up: bingo, it has a name.

That's how it works, not the other way around. It's formalization of real life, not theory to apply.

comment 5y ago · link · parent

It's also because the britanic banking system decided that, on the safety / usability balance, they would choose usability.

Banking in britanic banking system is way easier than anywhere else. I remember when I was a student, they sent a bus to the university, so we could just hop in, arrive at the bank, and open an account as an immigrant in 15 minutes.

Try to do that in France, you would get your card, what, next month at best?

It was only a matter of time before the criminals realize the door was unlocked and feast on them.

In fact, I'm expecting Australia to be next, for the very same reasons.

Have you tried to do any paper work in Australia ? It's. So. Simple. Seriously, for a french, it's a video game on easy mode, and you never leave the tutorial.

But there is trust everywhere.

They are either going down, or make the system harder to work with.

comment 5y ago · link · parent

Unless the fraudulent transaction is due to the fact you just lost your credit card.

comment 5y ago · link · parent

Sure, like anyone can be Usain Bolt if they are familiar with their body and has a deep understanding of running.

comment 5y ago · link · parent

I'm so waiting for somebody selling pieces of the moon as NFT, like the good old 1900 scams.

They already redid the million dollars home page, NFT edition.

comment 5y ago · link · parent

You can follow the answers to the announcement on the mailing list here: https://mail.python.org/archives/list/python-dev@python.org/...

TL;DR: the author has working code for a CPython 3.9 implementation that gets rid of the GIL, works with most C extensions (albeit requiring to compile them again), and with better perfs _including_ for single threaded programs.

The report is worth read, very clear, professional, and humble, which for such a complex achievement, is quite a thing by itself.

1
117118119
184