Hacker Newsnew | past | comments | ask | show | jobs | submit | more BiteCode_dev's commentslogin

I though you were joking. But no.

A widget doing:

    0 ----------[37]------------------ 100
Is 17kb, __gzipped__. Compressed. Archived.

It's 3ko more than the entire front page of Hacker News, including all the content and assets, after zipping.


I think it's all those videos/gif in autoplay.


Nah, its throwing a ton of Promise errors.


I don't think it's going to be a fairly high price point. Satellites are becoming commodities, Space X drove the price of launching down, and with the current technologies a small computer can process a lot, especially if you don't have to care about heat dissipation. Quite the contrary, you don't need to construct many towers in cities to get coverage, with all the legal burdens that implies and all the maintenance it requires. You will cover a much broader space, so your potential customer base is bigger for the investment, and you can even cover places that would have not been before. In fact, you can even have better signal for moving people like in trains, cars or... boats and planes !

Of course this is all speculations, but it has a lot of potential.


And anybody can make an amazon review. Very few people have the skills required to peer review a scientific paper.


jupyter-notebook is not meant for that. It's meant for code and data exploration. If you dev something using the notebook, you are doing it wrong. That's what IDE are for.


Besides, you have only access to the text. A website like Amazon has a huge list of additional data points to make guesses.


Don't follow this blog post advice.

Manually dealing with threads and processes is useful if you want to build a framework or a very complex workflow. But chances are you just want to run stuff concurrently, in the background.

In that case (which is most people case), you really want to use one of the stdlib pools: it takes care of sync, serialization, communication with queues, worker life cycle, task distribution, etc. for you.

Plus in such case, waiting for results is super easy:

    import time
    import random

    from concurrent.futures import ThreadPoolExecutor, as_completed

    # the work to distribute
    def hello():
        seconds = random.randint(0, 5)
        print(f'Hi {seconds}s')
        time.sleep(seconds)
        print(f'Bye {seconds}s')
        return seconds

    # max concurrency is 2
    executor = ThreadPoolExecutor(max_workers=2)
   
    # submit the work
    a = executor.submit(hello)
    b = executor.submit(hello)

    # and here we wait for results
    for future in as_completed((a, b)):
        print(future.result())
Want multiple process instead ? It's the same API:

    import time
    import random

    from concurrent.futures import ProcessPoolExecutor, as_completed

    def hello():
        seconds = random.randint(0, 5)
        print(f'Hi {seconds}s')
        time.sleep(seconds)
        print(f'Bye {seconds}s')
        return seconds

    # Don't forget this for processes, or you'll get in trouble
    if __name__ == "__main__":

        executor = ProcessPoolExecutor(max_workers=2)

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

        for future in as_completed((a, b)):
            print(future.result())
This is Python. Don't make your life harder that it needs to be.


This example still involves a lot of manual work. It's often times even easier.

    from concurrent.futures import ProcessPoolExecutor
    import string
    
    def hello() -> int:
        seconds = random.randint(0, 5)
        print(f'Hi {seconds}s')
        time.sleep(seconds)
        print(f'Bye {seconds}s')
        return seconds
    
    # Don't forget this for processes, or you'll get in trouble
    if __name__ == "__main__":
    
    inputs = list(string.printable)
    results = []
    
    # You can sub out ProcessPool with ThreadPool. 
    with ProcessPoolExecutor() as executor:
        results += executor.map(hello, inputs)
    
    [print(s) for s in results]


"with" is always a good idea indeed.

But be careful, map() and submit() + as_completed() don't have the same effect.

The first one will give you the result in the insertion order, while the later give you the results in the order they are completed.


The code needs some minor changes (imports, missing parameter and indent) to make it runnable.

  from concurrent.futures import ProcessPoolExecutor
  import string
  import random
  import time

  def hello(output) -> int:
    seconds = random.randint(0, 5)
    print(f'Hi {output} {seconds}s')
    time.sleep(seconds)
    print(f'Bye {seconds}s')
    return seconds

  # Don't forget this for processes, or you'll get in trouble
  if __name__ == "__main__":

    inputs = list(string.printable)
    results = []

    # You can sub out ProcessPool with ThreadPool. 
    with ProcessPoolExecutor() as executor:
        results += executor.map(hello, inputs)

    [print(s) for s in results]
EDIT: I also struggle with proper code indentation on HN.


Quintessential HN, top comment totally disapproves the posted article. Thanks. I was just having an issue with this and was excited to see some gains with the link here and then to see there's an even better way is terrific!

If you wouldn't mind going into a little more detail about what you're doing I'd really appreciate it!


> If you wouldn't mind going into a little more detail about what you're doing I'd really appreciate it!

What do you want to know ?


That is true. Python has better ways to deal with concurrency. As I wrote elsewhere in comments, I started reading asyncio. But found that for a newbie this article is good to grasp basic concepts.


What if you are waiting on something that is not your Python code?

What about this?

https://github.com/rwarren/SystemEvent


You put the call in a function where you wait for it, and pass it to the thread pool.

Or you use asyncio for network based stuff.


> Or you use asyncio for network based stuff.

Only if you really need to. For 99% of network needs, using pool executors is simpler and easier than asyncio and it's one less only-sort-of-useful thing to have to learn.


We are getting there. asyncio in 3.7 is now quite ok to use.

Plus, I'm working with andrew sveltov on a new API for aiohttp, so that you can do:

    def main():
        response = await aiohttp.get(url)

    asyncio.run(main())

It should make at least the most common use case of asyncio way more easier.

The biggest problem is that I have yet seen a tutorial that explains properly how to use asyncio.

They all talk about the loop, and future, etc..

First, they all should tell you that asyncio should be used only with Python 3.7+. Don't even bother before. Not that it's not possible, but I've done it, and it's not worth the trouble.

Then, all tutorials should mention wait() or gather(), which are the most important functions of the whole framework. It kills me to never see those explained.

With just that knowledge, you can script happily at least as easily as with the pools I just had show case.

Now, I really hope that we are going to get trio's nurseries imported in the stdlib. yury selivanov is working on it from uvloop, so I got good hopes.

I did a proof of concept as an asyncio lib and it works decently, but having a standard would be much, much better.


Only one dependency "posix_ipc >= 1.0.0".


Great example. Can I ask how I would discover or remember this import line, in case I forget?

I often remember useful standard libraries that I hear about by name, after using them once, but this is a long one.

Alternatively - is this an example in the python readthedocs yet? I try to fall back to that when possible, so my code stays simple for others.


I don't. I have a huge knowledge base I store on my computers with those kind of things. E.G: this snippet is actually almost verbatim a file I have on my laptop I wrote months ago and kept so I don't have to rewrite that again.


This is solid advice.


I like the idea, but wanted to know how realistic it would be so I made a quick and dirty Python script to download all my bookmarks. If you want to make the same experiment, you can get it from here: https://gist.github.com/ksamuel/fb3af1345626cb66c474f38d8f03...

It requires Python 3.8 (just the stdlib) and wget.

I have 3633 bookmarks, for a total of 1.5 Go unziped, 1.0 Go zipped (and we know we can get more from better algo and using links to files with the same checksum like for JS and css deps).

This seems acceptable IMO, espacially since I used to consider myself a heavy bookmarker and I was stunned by how few I actually had and how little disk they occupied. Here are the types of the files:

   31396 text/plain
   3034 application/octet-stream
   1316 text/x-c++
   1123 text/x-po
    865 text/x-python
    384 text/html
    227 application/gzip
    218 inode/x-empty
    178 text/x-pascal
    113 image/png
     44 application/zlib
     29 text/x-c
     28 text/x-shellscript
     14 application/xml
     13 application/x-dosexec
     12 text/troff
      5 text/x-makefile
      4 text/x-asm
      3 application/zip
      2 image/jpeg
      2 image/gif
      2 application/x-elc
      1 text/x-ruby
      1 text/x-diff
      1 text/rtf
      1 image/x-xcf
      1 image/x-icon
      1 image/svg+xml
      1 application/x-shockwave-flash
      1 application/x-mach-binary
      1 application/x-executable
      1 application/x-dbf
      1 application/pdf
It should probably be opt-in though, like a double click on the "save as bookmark icon" to download the entire file, and the star becomes a different color. Mobile phones, chrome books and raspy may not want to use the spaces, not to mention there are some bookmark content that you don't want your OS to index, and show you preview of in every search.

But it would be fantastic: by doing this experiment I noticed that many bookmarks were 404 now, and I will never get their content back. Beside, searching bookmark, and referencing them is a huge pain.

So definitely something I wish mozilla would consider.


> definitely something I wish mozilla would consider

There used to be this neat little extension called Read It Later that let you do just that. Bookmark and save it so you could read it when you were offline or the page disappeared. Later they changed their name and much later Mozilla bought it and added it to Firefox without a way to opt out. It was renamed to Pocket.


Pocket is not integrated with your bookmarks. For offline consultation, you need a separate app. Of course this app is not available on Linux, where you have to get some community provided tools.

Bookmark integration would mean one software, with the same UI, on every platform, and only one listing for your whole archive system.


The author says:

"that formerly beloved browser feature that seems to have lost the battle to 'address bar autocomplete'."

But at least in firefox, if you type "*" then your searched terms in the URL bar, it actually queries your bookmarks !

There are many such operators, you can search in your history ("^"), your tags ("+"), you tabs ("%"): https://support.mozilla.org/en-US/kb/address-bar-keyboard-sh...

My favorite is "?", which is not documented in this link. It forces search instead of resolving a domain name.

E.G: if I type "path.py", looking for the python lib with this name, Firefox will try to go to http://path.py, and will show me an error. I can just add " ?" at the end (with the space) and it will happily search.

It's a fantastic feature I wish more people knew about.

It very well done as well, as you can use it without moving your hands from the keyboard: Ctrl + l gets you to the URL bar, but Ctrl + k gets you to the URL bar, clears it, insert "? ", then let you type :)

It's my latest FF illumination, the previous one was discovering that Ctrl + Shirt + t was reopening the last closed tab.


Not sure you're aware of this one too... But, you might like the "Ctrl+Tab" shortcut as well. With it you can alternate between the last few active tabs, with thumbnails. Really handy.


I don’t think I’ve come across a single Firefox user that ever uses keyboard shortcuts that has left it that way—all have found the “Ctrl+Tab cycles through tabs in recently used order” preference and turned it off, so that it goes through tabs in order, like literally every other program I’ve ever encountered does with tabs. (Yes, Alt+Tab does MRU window switching, but that has never been the convention for Ctrl+Tab tab switching.)

Mind you, MRU switching is still useful behaviour; Vim has Ctrl+^ to switch to the alternate file which is much the same concept, and Vimperator et al. used to do the same (on platforms where Alt+number switched to the numbered tab, rather than Windows’ Ctrl+number), no idea whether equivalent extensions can do that any more. I have a Tree Style Tab extension that makes Shift+F2 do that, and it suits me.


If you keep Control+Tab set to cycle through tabs in recently used order, you can use Command-Shift-Left/Right or Control-PageUp/PageDown to cycle through tabs in tab-bar order instead.

Additionally, you don't need an extension to jump to a tab anymore. Command-[1-8] goes to that number tab in the current window, where 1 is the leftmost tab. Command-9 goes to the rightmost tab.


At least on linux, that shortcut does not use an MRU ordering; I see other replies mentioning the command key; is this behavior Mac specific?


Thank you so much for this! Another handy and often overlooked feature are the shortcuts for bookmarks. And with %s in the URL you can search/navigate pretty fast. Example: https://en.wikipedia.org/wiki/%s with the shortcut "w" could bring you the according article if you type "w foobar"


Performances and money. You don't want to make the db, cache and network operations to get the comments for every users, only those who really want to read them which are not most of them. At the size of google, you save millions or dollars with such trick.


At the cost of a crappy and sluggish user experience, of course


Everything is a matter of compromise. What's important is to make them consciously, which I believe Google did in that case.


Yet they insist on auto-playing the next video when most users will not be interested in that. Serving all comments is much less data than even the initial buffer of the video. The real reason I think is that a user reading comments on youtube isn't watching ads during that time.


Auto-play means more views means more ads means more money, yet. But I don't think it's the same for comments.

Comments don't have adds. They are a feature that cost money, but don't bring any.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: