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 6y ago · link · parent

They noticed apple mostly got praises and money for it, while going standards means competition and losing control.

Both bring angry geeks for different reasons, but as long as most people reward them for being locked up in a closed ecosystem, I don't see why they would change.

comment 6y ago · link · parent

As vlc proved before, you can be open and play drm protected content.

Some countries make it illegal, but France doesn't so I'd be happy to have such device.

comment 6y ago · link · parent

Complaining about them being useless and bringing down the signal/noise ratio is ok too, then, I guess.

But jokes aside, this is why we have sites like HN. To avoid the noise.

comment 6y ago · link · parent

A twitter account RT with emoji, people block it because it has no value, and it's called news?

Don't get me wrong, I find it funny. The current trend of humble brag is a good topic to laugh about.

But do you want an entire article about this? Do you want that to be on HN front page?

There are thousands of such joke accounts. Are we going to post about them all?

comment 6y ago · link · parent

There are been many attempt to create a different design without the GIL. None of them made it to cPython.

The whole language assume it's safe to mutate things around. E.G: list.append() is assumed to be thread safe.

comment 6y ago · link · parent

Not a core dev.

The clean way to return a value is to pass it to a Queue (https://docs.python.org/fr/3/library/queue.html), and this is what the executor does, but for your use case, it's overkill.

For very simple use cases, you can inherit from Thread and force join() to return the value:

    class SimpleReturningThread(Thread):
        result = None
        def run(self):
            try:
                if self._target:
                    self.result = self._target(*self._args, **self._kwargs)
            finally:
                del self._target, self._args, self._kwargs
        def join(self, *args, **kwargs):
            super().join(*args, **kwargs)
            return self.result

Personally, I'd stick to using a pool with only one worker in it. It's not worth the trouble of doing all this work. Wrap it in a few functions if you do the same thing repeatedly and call it a day, it's unlikely going to be what most your code is about anyway.

comment 6y ago · link · parent

Just create a new pool and close the previous one, depending of the system load.

comment 6y ago · link · parent

I get that this guide tries to ease you in into low level concurrency concepts.

However, if you try to just get work done in Python, this is not what you want.

Don't do threads/processes yourself, use pools:

    import random
    import time
    from concurrent.futures import ProcessPoolExecutor, as_completed

    def hello():
        seconds = random.randint(0, 5)
        print(f"Start blocking for {seconds}s")
        time.sleep(seconds)
        print(f"Stopped blocking after {seconds}s")
        return seconds

    if __name__ == "__main__":

        with ProcessPoolExecutor(max_workers=2) as exec:

            a = exec.submit(hello)
            b = exec.submit(hello)

            for future in as_completed((a, b)):
                print(future.result())
And don't manage the loop yourself. Use Python 3.7, and replace:

    loop = asyncio.get_event_loop()
    loop.run_until_complete(loop.create_task(foo()))
    loop.close()
With: asyncio.run(foo())

The code is not just shorter, it is way, wayyyyyyyyyyyy, more correct.

Also don't program asyncio by hand. Use a lib. E.G: wanna do http, use aiohttp.

This is Python, don't suffer more than you need to.

comment 6y ago · link · parent

Python always could use multiprocessing to do parallel processing leveraging several CPU.

However, it became especially easy with Python 3.2 (10 years ago) which introduced the ProcessPoolExecutor (https://docs.python.org/dev/library/concurrent.futures.html#...):

    import random
    import time
    from concurrent.futures import ProcessPoolExecutor, as_completed


    def hello():
        seconds = random.randint(0, 5)
        print(f"Start blocking for {seconds}s")
        time.sleep(seconds)
        print(f"Stopped blocking after {seconds}s")
        return seconds

    if __name__ == "__main__":

        with ProcessPoolExecutor(max_workers=2) as exec:

            a = exec.submit(hello)
            b = exec.submit(hello)

            for future in as_completed((a, b)):
                print(future.result())
The same exact same API exist for thread BTW. I don't think a tutorial should introduce you to concurrency using manual process/thread management any more. I makes no sense to me.

You may note that multiprocessing still eats more RAM than with typical Go/Rust code since max_workers=n means n+1 Python VM spawing but on modern servers you don't really feel it. That's what most WSGI setup do anyway.

Now, before 2019, there was one more use case that wasn't served well: how do you share some computation between isolated processes that need to communicate to make their work ? Typical use case was people using numpy or pandas crunching numbers that depended on each others. Indeed, communicating between processing using piping is expensive given the cost of message passing serialization.

However, in the previous Python release (3.8), we introduced a mechanism to share memory for almost free (https://docs.python.org/3/library/multiprocessing.shared_mem...):

    from multiprocessing.managers import SharedMemoryManager

    with SharedMemoryManager() as smm:
        sl = smm.ShareableList(name="unique_name", range(2000))
The sl object can then contain int, float, bool, str, bytes and None and its reference can be shared among processes. Each item can be deleted and replaced. You an also get an hold on sl by using the "unique_name" if you don't have the reference at hand.

There is a raw ShareableMemory object for stuff like numpy/pandas array buffers if this is your main concern.

comment 6y ago · link · parent

If it's not standard, it will be useless. If it is, the browser will eventually put it in the users hand.

comment 6y ago · link · parent

Yes, but doing so, they will lose the ability to be indexed, searched, archived and linked to. Like during the flash era.

Which in turn will start a new trend of website that are "open".

It's a cycle.

comment 6y ago · link · parent

There are many cases where what you need is instant soup powder, not home made velouté.

And this will save me from writing tests for those lines. With all major browsers. And documentation. And maintain all that, of course, for the next 5 years.

And when new devs will arrive in the team to provide the training for the custom code. I may even not be here anymore

So yes, it can be overkill, or just what you need.

E.G: some server side dev need a quick fix for his personal web site.

Besides, even a lib with zero tests like this one will have enough users and tickets open that it will be better tested that the server side dev code that don't know JS much.

comment 6y ago · link · parent

Startup idea: use machine learning to scan social networks and detect PR campaigns, submarine pieces, fake reviews, etc.

comment 6y ago · link · parent

Ok, the more I read answers to my comment, the less I think it's a good idea.

comment 6y ago · link · parent

Didn't think of that.

It doesn't have to be just the state or the UN though. It's not about removing all the other actors on the market.

But if I make a website on Python programming in french, I'm quite ok using the french gov as a CA provider.

I mean, I trust mozilla because it's mozilla. But I wouldn't trust most companies.

comment 6y ago · link · parent

This should be a state provided service. Or provided by the UN. Essential stuff like this or root DNS should be a planetary responsibility.

comment 6y ago · link · parent

In JS speech, I said "==", and you said "!==".

comment 6y ago · link · parent

Quite the contrary, as shown by as most dictatorships across the world trying to control their piece of the internet. The biggest example being the Big Firewall of China.

This let them control how people think, communicate, consume and inform them-self. But also detects anyone that could oppose the regime. Or make a graph of all allies, suspects, etc.

Then you hit them with a rubber hose :)

comment 6y ago · link · parent

Same.

Gotta also make sure I don't get a US Firefox build somehow.

comment 6y ago · link · parent

I supposed not having a dictatorship regime in your country history book helps to see things that way.

Given the way my country went from freedom to "regime de Vichy" in a few years, during my grandpa time, I don't want a state level entity having that kind of power.

Since the US state level entities decided they could now ignore Habeas Corpus and legitimated torture, secret courts and declared impunity for them-self, I especially don't want them to have that kind of power.

comment 6y ago · link · parent

Nowhere it says they have no plan of doing it. They just release it only for the US __build__, __by default__, __now__.

But to make things more honest, I'll edit my comment.

comment 6y ago · link · parent

Cloud flare is American and we know since the PRISM scandal that US based tech companies are directly plugged into the NSA, and everybody in the chain will deny it under the threat of prison.

So, if this rolls out 'as-is' in any other country than the US, we will go from "all DNS requests are clear text, but dispatched among many entities" to "DNS requests are encrypted, but all read and controlled by american agencies".

We (may) have gain (some) privacy (maybe). But we also (certainly) gained a serious dependency.

comment 6y ago · link · parent

Because students can understand "code being run every x seconds" easier than "reference to function being resolved then called every x seconds".

Once they do, you show the problems with it and show why callbacks are better.

When it comes to pedagogy, I'll use every trick I can.

And I always win.

comment 6y ago · link · parent

> which means an operation might be executed zero or multiple times depending on the bind.

That's what the jQuery API does behind the scene of the chained calls. That's one of the key reasons of its success actually.

$(".foo").foo().bar() will execute n times, for each of the n DOM elements you matched with ".foo", including one or zero.

comment 6y ago · link · parent

"sane" is the keyword here.

The alternative all depended on non technical users with slow connections to install the runtime.

Js code was guaranteed to work anywhere, and with no requirements, giving it practical monopoly.

comment 6y ago · link · parent

I don't think it is. If JS had any sane competition, I think it would have lost. By some weird conjunction of events, it landed a monopoly on the most amazing plateform in the world.

PHP is a good example of Worse is Better, because it won over the competition, despite its flaws.

HTML vs xHTML as well. Bash, maybe?

But JS didn't win. It was the only one there.

comment 6y ago · link · parent

Wow, I just tried:

    setInterval('console.log(1 + 1)', 1000);
And it works. It's a big eval().

Stealing this for my next JS training, beginners always have a hard time with callbacks, so it's a good first step to actually explain the benefits of callbacks.

comment 6y ago · link · parent

How would you express "would like"?

"I don’t want to go" and "I would like not to go" express different things.

One is expressing opposition right now, the other one is expressing desire or even a request, potentially while the action is already engaged. The first one is definitive, the second one is wishful thinking or negotiation.

comment 6y ago · link · parent

For Haskell, when doing:

    $("foo").stuff().bar().res() 
jQuery feels like the list monad, if you see chaining as similar to bind and $() not so far from return.

And for Lisp, jquery provided error handlers instead of relying on native try/except.

Of course, it's more inspired from it than the real thing, but it's far from any JS paradigm of the time. Remember that JS didn't even have map() and the only place you used your first class functions was to setInterval. Plus the joke is funnier that way :)

comment 6y ago · link · parent

Most server side code is Java, quickly followed by PHP.

And of course next to JS, you have C#, Asp.Net, Ruby, Python, and Go.

I'd say that given that:

- a lot of people only know JS (like designers)

- JS has a monopoly on the front end and is the only language that can be used on the front and back

- JS has existed for as long as Java (C#, Ruby and Go are way younger)

- there are JS materials everywhere given the web popularity

- the web is the most popular plateform in the world

The fact, as a freelancer going from company to company, I see so little JS on the server compared to other languages tells a lot.

1
175176177
184