Threads for sebst

  1. 7

    No thanks, that’s quite expensive just to host some side projects. The basic setup with a container registry and a 2 node Kubernetes cluster will cost you 44$/month.

    1. 2

      You can start with as little as $12/mo – one node cluster, free tier registry.

      1. 1

        That’s true, but I didn’t consider the free tier since it is very limited. Just 1 repository and 500mb of storage, that’s maybe one to two large container(s).

    1. 1

      Thanks for yet another post! I noticed quite a few more typos this time around though, not sure if I’m the only one bothered by those:

      • “VSCode docker containers straight ro production”
      • “Learn Kubernetes alon the way”
      • “Make sure you chnage the registry accordingly”

      There were also multiple instances of casing being off (e.g. “docker container” vs. “Docker container”, “yaml files” vs. “YAML files”, etc.). This isn’t to throw shade on you or anything, I truly appreciate your continued effort in authoring posts.

      To anyone else getting started with K8S based tools like kubectl and helm I suggest taking a look at Hermit as it makes installing not only those tools but other ones as well dead simple. Here is a list of tools that can currently be installed. I’ve also submitted a PR to add doctl into the mix.

      At work I’ve used Hermit to greatly simplify installing common tooling by removing the requirement that people go through various bits of documentation on various sites to just running, for example, hermit install gcloud helm kubectl kubectx kubens velero.

      1. 1

        Thanks for the hints on the typos! I changed it!

        hermit is a great tip; thank you!

      1. 1

        I will plan a trip to California, Santa Barbara, and San Francisco, to be precise. Is anyone up for a coffee? Will be my first trip to the States…

        1. 1

          I’m working on more Python content on my blog and Twitter (https://bas.codes, https://twitter.com/bascodes) and preparing my proposals for DjangoCon Europe

          1. 6

            Just a little nit, but args in def fn(*args): will actually be a tuple and not a list (so you can’t push or pop from it).

            1. 3

              Good catch, thank you. I’ll update it!

              1. 8

                I believe it’s also most correct to say that * works with any iterable and ** works with any mapping — that’s a much broader scope of things than just list and dict.

            1. 9

              This is a great article. Thanks for writing it!

              It’s a perfect example of a language feature that many of us use from time to time, but also either don’t or barely understand what’s going on under the hood.

              1. 5

                Glad that you found it useful

                1. 3

                  Clear, concise, to the point. Full marks!

                  1. 2

                    I also liked it very much. Just an excellent presentation of a surprising if not esoteric technical topic. Thanks.

                1. 2

                  Traveling to Berlin for PyConDE

                  1. 2

                    PEP 654 … introduces ExceptionGroups. With them, we’re able to raise multiple exceptions simultaneously

                    I’m not familiar with the pattern of raising multiple exceptions. What other languages support this? I’m interested to see where and how they become useful.

                    try:
                        raise ExceptionGroup("Validation Errors", (
                            ValueError("Input is not a valid user name."),
                            TypeError("Input is not a valid date."),
                            KeyError("Could not find associated project.")
                        ))
                    except* (ValueError, TypeError) as exception_group:
                        ...
                    except* KeyError as exception_group:
                        ...
                    
                    1. 4

                      The ExceptionGroups has primarily been introduced to support proper error handling in the asyncio TaskGroups

                      1. 1

                        That’s interesting. In Go, I have a multierror that I use to consolidate errors when running concurrent gorountines. Of course, errors are just a normal interface in Go, so it’s pretty easy to just add an Error method to a slice of errors. It doesn’t need any special language support.

                        I wrote a gist to try to combine Python exceptions once, but it was sort of a kludge. It’s nice that it will be a first class thing now.

                        1. 1

                          That’s basically what asyncio.gather() already does, but PEP 654 exists to make the process less cumbersome.

                      2. 3

                        It’s not built-in, but if I’m understanding the feature correctly it wouldn’t be difficult to do with Common Lisp conditions.

                        1. 1

                          This reminds me a bit of pydantic: if you have errors in your model it should give you multiple validation errors instead of blowing up on the first one. Maybe it would also be useful in that context?

                          1. 4

                            I don’t think it’s for that use case. Within a single library, you can do:

                            from typing import List
                            
                            class ValidationError:
                                line_number: int
                                reason: str
                            
                            class ValidationErrors(Exception):
                                errors : List[ValidationError]    
                            

                            So based on above discussion it sounds like it’s more about combinations of multiple different exceptions.

                            1. 2

                              Django’s forms library has something similar; instead of forms having a potential attached error, they have a a potential list of attached errors, produced by catching and collecting every django.forms.ValidationError raised during the validation process.

                              1. 1

                                Seeing as we’re talking about new features in recent versions of Python, you don’t need from typing import List anymore, since 3.9 you can just write:

                                class ValidationErrors(Exception):
                                    errors: list[ValidationError]
                                
                                1. 1

                                  Good to know! And I guess I actually have one project where I can use Python 3.9 features, but everything else only just dropped 3.6. Going to be a while…

                                  1. 1

                                    TIL that you can do from __future__ import annotations as of Python 3.7 for this.

                            1. 1

                              Thanks for yet another wonderful overview! I would love it if you could cover the world of testing in Python as well. I’m struggling to wrap my head around how exactly mocking, monkeypatching, and fixtures intermingle.

                              1. 1

                                That’s a great idea! Thank you, I will try to cover it in the next weeks

                                1. 1

                                  Blessed art thou!

                              1. 7

                                I will help two non-technical people to understand the basics of Python by building a robo car!

                                1. 2

                                  That is totally awesome! What environment will you use to help them get going? I know Mu has a bunch of built in support for interacting with robotics and IoT platforms.

                                  1. 2

                                    I use a kit by Sunfounder – initially, I wanted to use a micro:bit but my order was not fulfilled.

                                    We use Thonny as IDE.

                                    Didn’t know about Mu, will for sure have a look at this! Thanks!

                                1. 7

                                  What would be a Pythonic way to implement a singleton-ish pattern?

                                  class Borg:
                                      _shared_ = {}
                                      def __init__(self):
                                          self.__dict__ = self._shared
                                  

                                  You may already know this, but that’s not the usual Python way to implement a singleton - usually a singleton is implemented by overriding __new__. This Borg is much less singleton-y because two Borg instances won’t compare as equal.

                                  Also, singletons are bad http://www.object-oriented-security.org/lets-argue/singletons

                                  1. 6

                                    There are cases where you need something like a singleton, but the right way to do that in Python is just to have one named instance in a module, and its “singleness” comes from the fact that you are importing foo from bar, and imports are a shared global namespace.

                                    1. 3

                                      The enum module in the standard library is one example where that approach to singletons does not work and you need to override __new__.

                                    2. 2

                                      You’re absolutely right: Two borgs don’t compare as equal (using id(borg_1) == id(borg_2)) but everything inside is the same.

                                      My point was not to make a case for singletons (or borgs) as I outlined in the article:

                                      Note that you should use singleton classes only occasionally because they introduce some global state in your program, which makes it hard to test individual components of your program in isolation.

                                      Instead, I wanted to illustrate how Python manages attributes.

                                    1. 3

                                      Interesting although I think singletons like this can make unit testing difficult, can’t they?

                                      1. 3

                                        Like anything else which holds a global state, yes; borgs make unit testing difficult in the same way as regular singletons do.

                                      1. 1

                                        Depends on what you want to analyze. I found sentry to be very useful as it gives me insights into Performance and Issues.

                                        1. 1

                                          Interesting, hadn’t thought about that one. I’m thinking about web specific values, for example: which api endpoints are used most by which user-agent. Would that be possible?

                                          1. 1

                                            Probably not easily. Sentry is more focussed on catching errors and providing stats about performance. If your use cases are more like the one described, I’d go with a simple access log parser (as suggested by @acatton)

                                        1. 2

                                          Anybody have ideas why IPv6 adoption is consistently higher on the weekends?

                                          1. 8

                                            It’s almost certainly personal use. This is due to many company networks not having DSlite, but also due to people being on mobile data plans on phones and tablets, which are a big driver for IPv6 usage as well.

                                            1. 0

                                              Exactly. It’s the time when folks have the leisure time to take advantage of Comcrap offering a fully native IPV6 experience to consumers (like I did).

                                              1. 1

                                                To the person who marked this comment a troll: Was it my use of “Comcrap” which I’ll admit could be seen as inflammatory? Because I was dead serious. Most of us working stiffs don’t have time to embark on a project like IPV6-ifying our home network except on the weekends when we can afford to screw it up and be down for an hour or two while we google solutions on our phones :)

                                                1. 2

                                                  Was it my use of “Comcrap” which I’ll admit could be seen as inflammatory?

                                                  Yes.

                                                  1. 1

                                                    Thank you for your candor.

                                                    I of all people should be more sensitive about tarring employees of large corps with one brush, working for AWS myself and cringing on a regular basis when every Tom, Dick & Harry in the known universe blames me for every bad experience they ever had when the UPS guy spat on their package.

                                                    Similarly, you (whoever you are, and assuming you’re a Comcast employee) aren’t responsible for the numerous install and provisioning experiences that left my wife & I ready the climb the walls.

                                                    I will sincerely try to be better about this.

                                                    For what it’s worth I really appreciate Comcast’s consumer IPV6 rollout. I was able to flip a switch and convert my entire LAN, and everything worked like a charm.

                                            2. 3

                                              A simple guess based on my observations in Germany right now: Many people have IPv6 connectivity at home, but not at work. Even many (most?) universites don’t provide IPv6 in their networks, especially on wireless. However, my private ISP does, and so do many others. The situation is similar in Austria, and (to my knowledge in France), so I’d expect it to hold in other places too and probably account much of this difference.

                                              1. 1

                                                I can confirm that the situation is similar in France. IPv4 at work, IPv6 at home and on my phone over LTE.

                                              2. 3

                                                There’s more IPv6 at home than at work.

                                                Why, I hear you ask. I don’t really know. My theory is that home users tend to get v6 when an ISP decides to upgrades everyone’s DSL/fiber middleboxes, while companies often have more hardware. If any of the hops from my desk to the network is v4-only, then so I am I. Home users wait for an ISP to enable v6, business users wait for all of n hops to enable v6, where n≥1. Even if n is only slightly greater than 1 on average, that will introduce some random lag compared to home users.

                                                1. 1

                                                  In the US, at least one major cell carrier (T-Mobile) uses IPv6 for their mobile data network, so all handsets connect with IPv6.

                                                  1. 1

                                                    Oddly enough, I’ve heard an anecdote involving that that selfsame name. As you may know, the IPv4 allocation rules were tightened several times at predefined points in time as the End grew near. One of the 2-3 relevant Deutsche Telekom companies was a bit late with requesting more address space from RIPE a while ago, and was one of the first ISPs to have a big address space application rejected.

                                                    All of its competitors had enough address space to grow for a while without any v6 deployment hurry, having gotten allocations in just before the rule change, but not Deutsche Telekom.

                                                2. 1

                                                  Maybe personal ISP plans are more likely to use DSlite or similar technologies? They can adapt faster while company plans still “need” fixed IPv4 addresses for VPN and other services

                                                  1. 1

                                                    My cable provider is dual stack, but by default the IPv4 is carrier grade NAT and the v6 is native. Modern OS prefer v6 over v4, but there is more v6 in customer network than in offices.

                                                  1. 1

                                                    Signed up. Nitpick, but it says Verification successfully instead of Verified successfully.

                                                    1. 1

                                                      Thank you for signing up. Fixed the typo as well!

                                                    1. 6

                                                      Cool! Nice to have a Python-specific site that isn’t a sub-Reddit.

                                                      @sebst I tried to verify my email and got a 500 error, BTW, so might want to check the logs…

                                                      1. 2

                                                        Thanks for the hint! I’ll have to investigate! Your account works fine without verification, though

                                                        1. 2

                                                          Should be fixed.

                                                          1. 2

                                                            I’m working on feeds! Hope to provide an update soon!

                                                          1. 10

                                                            Arc - Bel - what’s next, Cex?

                                                            1. 7

                                                              Arc was released 11 years ago says Wikipedia. So Cex is due in 2030.

                                                              1. 2

                                                                I don’t get this…

                                                              1. 1

                                                                Congratulations! What is your caching story right now–it seems a little slow to revisit some pages?

                                                                1. 1

                                                                  At the moment there is no caching. However, it’s slower than it should be. Need to tweak some elastic beanstalk settings, I guess

                                                                1. 3

                                                                  Congrats, but I have to ask: why such a tiny default font? To be able to comfortably read the contents, I need to have 140% zoom.

                                                                  1. 1

                                                                    It’s designed as a clone of Hacker News. To evolve from this, also from a frontend point of view, is on my list ;-)

                                                                    1. 2

                                                                      Too bad you didn’t use lobsters to do that! We would have had another sister site!

                                                                      Anyway good job and good luck with this project!

                                                                      1. 6

                                                                        I considered this. But I thought a python site cannot be done in Ruby ;)