24,628 karma · joined Oct 21, 2019 (7y ago) · 5,512 submissions
https://www.bitecode.dev/
Email: contact at bitecode.dev
comment 6y ago · link · parent
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
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
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
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
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
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
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 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
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
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
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
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
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
"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
$("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
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.