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

> A recent example is WakaTime, who replaced Celery with a custom-built queue. This effort took one week to build and productionise, and consisted of just 1,264 lines of Python.

What a load of BS. Wakatime doesn't even have tests, has been used by one person and has no error handler. It's 1k lines because it's alpha sotfware.

Celery is not the most fun to play with, but it's not big for nothing. It supports many routers AND result stores, and you can mix an match. It has several policies regarding errors, has a beat daemon, provide an API for monitoring and managing (see: https://flower.readthedocs.io/en/latest/ for UI), etc.

Also, you can use celery in a very bare bone setup using only the FS for routing and storage: https://www.distributedpython.com/2018/07/03/simple-celery-s...

I understand you may want to avoid celery. I had bad experiences with it myself. Most projects can get away with rq, or even just multiprocessing.Pool.

> Before embarking on the mission of creating a new task queue do survey the existing options, but make sure not to underestimate the hidden costs of using one, or the benefits that may come with writing one from scratch.

Writting your own task queue is like creating your own csv parser. It seems like a very simple task that is barely a for loop with a split. And then you start hitting edge cases after edge cases.

Basically you are coding an asynchronous, fault tolerant process manager including task serialization, communication protocol, priority queuing and lifecycle.

That's not something you usually want to do. The cost of using one is unlikely higher that the cost of creating, maintaining and documenting one. Just go with a simple existing task queue if you need something simple. Pypi is full of those.


The task queue we built at Thread wasn’t much bigger, actually supported multiple queue backends, had tests, and has run millions of jobs a day for a decade. The team knows it very well, and it takes a few days a year to maintain, improve, and iterate to fit with new infrastructure.


The dirty secret about Python packaging problems is that a lot of them... are not relatated to packaging.

Python has first and foremost a big __bootstrapping__ problem, and the consequences of that are often seen when you try to install or use dependancies. So people conclude that packaging sucks.

Now don't get me wrong, packaging have some problems, but compared to most languages out there, it's actually pretty good.

But people cannot enjoy that, because they would have to install, setup and run python in a perfect sequence.

So what's wrong with Python bootstrapping, and why does it affect packages?

Well, as it is often the case in FOSS, it stems from too much diversity. Diversity is tooted as this one great thing, but its benefits also come with a cost.

- there are too many ways to install Python. Official installer, anaconda, Windows Store, pyenv, homebrew, Linux repositories... They all come with different configurations and lead to problems, such as anaconda being incompatible with pip or Linux default setup not providing pip.

- it's very common to have numerous and diverse python installed on your machine. Different versions, different distributions, sometimes embeded Python... Now it's your job to know which Python you start and how. But people have no idea you should use "py -3.10 -m pip --user install black" and not "pip install black" on Windows if you want a clean install at the system level. Yes, this weird command is the only clean way to do it outside of a venv. I'm not making it up.

- the variation between the different ways to run Python and the commands lead to confusion. "python", "python3.10", "py -3.10", "pip", "pip3", "python -m pip", "sudo pip"... There are many wrong ways to do it, and not many good ones, and it all depends of the distribution, the OS, and wether your are in a venv or not.

So how does that affect packaging? Well, people will get a lot of "command not found", and so they will google and paste commands until one works. There is too much to know, and they want a solution, not learning the whole graph of possibilities. Eventually they do something that seems to work, but they probably installed with admin rights, or in anaconda with pip, or in the wrong Python version. On import or on run, something will then break. Maybe now. Or worse, maybe in one month. And they have no way to understand why.

What's the short term solution for you?

- Always use the official installer on Windows and Mac. Don't use anaconda, don't use homebrew, don't use pyenv.

- If you have to use Anaconda (I would advise not to), don't use virtualenv and pip, use their own tool: conda and the anaconda prompt. You will be limited in packages, but it will work. Don't mix conda and pip.

- On Linux, you will have to figure out what magic packages you need to install to get a full Python setup, because linux distributions authors don't provide a full Python by default. It's different for each distribution and Python version sometimes. It must include pip, venv, setuptools, tkinter, ssl and headers. Good luck.

- Don't use Python outside of a virtualenv. Ever. I know how to do that correctly. You probably don't. So don't. Always create a venv for each project you work on, and activate it before doing anything. From there, you can use pip and Python in peace. E.G: Don't install black or jupyter outside of a venv. You want to use poetry? Don't let it create your venv. Create one, activate it, then install poetry with pip, the use poetry from there. I'm not kidding.

- On Windows, the command is "py -3.10 -m venv name_of_your_venv" to create it, with "-3.10" to be replaced with the version of Python you want. On Mac and Linux, the command is "python3.10 -m venv name_of_your_venv". Yes. Not a joke.

- To activate it, on Windows it will be name_of_your_venv\Scripts\activate", on Mac and Linux, "source name_of_your_venv/bin/activate.sh".

Any variation on this (including using -m or pipx, which I used to recommend but don't anymore) assumes you know what you are doing.

What's the long term solution?

I give some hints here:

https://twitter.com/bitecode_dev/status/1567790837848743937

And meanwhile, take the official survey on packaging, this will help pin things down for the team:

https://www.surveymonkey.co.uk/r/M5XKQCT


Definitely conda is more problem and less solution.


So... zombie cells cause by pollution?


If you work for one month and you are at the mercy of the other party to decide if they need to pay you, it's not any more easy money than the lottery.


I've definitely been there! Finding P1s for full read/write access and then seeing the report downgraded to a P3, and having to have the platform arbitrate and bump it back to P1.

However, it was this experience of mine as a part-time security researcher that actually led to us creating the bug bounty program for TigerBeetle's consensus.

For example, if you're looking at another database and find a correctness bug, there might not be a bounty program at all. Whereas with TigerBeetle, there hasn't been a single valid report that we haven't awarded, at least so far.

It's also why we were careful to rather be upfront and explicit about scope, than disappoint anyone after the fact.

And we recognize that consensus is hard and takes time to learn, hence the $8192 award for correctness finds.

That said, I hope you can see from the leaderboard that we've been generous. For example, Alex Miller found a bug in Apple's O_DSYNC and we nevertheless awarded $1024 because it was such a great find (Apple thought so too!).


$1024 is half my daily rate. I doubt someone find "a great find" in 4 hours. And not even time that is guaranteed to be paid.


I think they are pretty open about what they can afford to pay. If you have self selected to be worth $2000 a day due to expertise or necessity, then you know that you're not a good fit for them.

However many people are willing to put in the work, so why are you so critical of their program.

Do you think they are taking advantage of people who should charge more? Or do you think they will not get anyone good for such a low rate, and thus fool themselves into thinking they are secure?


To be clear, this was out of scope of the bounty, it was a bug in Apple, that TB awarded anyway.


Even before talking about the typing system itself, annotations existed by themselves and are not attached to any behavior in Python: they simply hold metadata.

When Python 3 came out, annotations were indeed added to the language, but no use case was decided for them. It was an experiment to see what the community would do with them instead of forcing a use case base on what the core devs would think would be useful.

In order to allow this, annotations where permitted to be any legal python expression.

Nowadays, type hints have won: annotations are widely used to add static type checking in Python. But the way the language treat them have not changed much appart from becomming lazy. While mypy cannot understand dynamic Python expressions in them, those are nevertheless legal syntax, and will result in correct metadata at runtime.

Therefore, were the typing system not turing complete, the annotations would have been anyway by nature of being basically an exec().


That’s not at all what’s going on here. While the Python interpreter permits and executes arbitrary expressions as annotations, Python static type checkers (mypy, Pytype, Pyre, Pyright) do not. This isn’t just an implementation limitation; the typing specifications (PEP 484 and successors) don’t allow it. For example, although these two definitions evaluate to the same result at runtime:

    def f() -> int: return 1
    def f() -> (lambda: int)(): return 1
only the first is correctly typed by PEP 484. mypy rejects the second with “error: Invalid type comment or annotation”.

That’s the whole idea of static type checking: in return for restricting yourself to a controlled subset of the language that isn’t “too dynamic”, you gain the ability to type-check your code without running it.

The result of this paper is that one can nonetheless abuse subtyping to perform Turing-complete computation in the type checker. The computation doesn’t happen when your code is executed (annotations have no effect on the Python interpreter at runtime unless your program chooses to inspect them), it happens when you run mypy on it.

This is generally considered undesirable, because we want type checking to be decidable, and Turing-complete computation is not.


> That’s the whole idea of static type checking: in return for restricting yourself to a controlled subset of the language that isn’t “too dynamic”, you gain the ability to type-check your code without running it.

Eh, you are mixing up distinctions.

All that's required of _static_ typing is that your static type specification finishes running before you start your program.

Whether that static type specification language is Turing complete or not is a completely separate issue. And, yes, you are right that it's generally useful for that language to be decidable. But see eg Haskell's UndecidableInstances.


That's why my comment litterally starts with "even before talking about the typing system itself".


I’m sure that you understood the important differences, but there are likely many readers who didn’t (many more programmers are familiar with Python than with mypy). When you write “even if we don’t have P, we’d have Q anyway”, the reader is left with the impression that P and Q are somehow interchangeable or equivalent or comparable—that P is unimportant in the presence of Q. I think it’s instructive to point out that this impression would be mistaken, and the paper’s result of P is interesting and consequential.


What other use cases did the community come up with?


Dependency injections, foreign-language bridges, data validation and parsing, etc.

But thanks to how we can introspect annotations, we could have a specialized syntax for types that would be also usable for those things, while the other way around would be harder.

So it's nice we went the type hints road, because you can now define types, and yet have wonderful libs like pydantic, fastapi, typer, taichi and so on.


Pydantic typing differs from mypy typing. Optional[T] means something different under the two.

I designed typedload before pydantic was a thing and I made it with mypy in mind already, and with the idea of using the standard library, not defining my own dataclass.

Unfortunately mypy has a limitation so you can't make a function that takes Type[T] and returns T. You can define it but it won't work for all types. There is still discussion on how to provide this feature.


Yeah this ones is really annoying with default values.


Cool, any examples of libraries that use it for dependency injection or FFI or validation?


Dependency-injector uses it for exactly this purpose

    @inject
    def main(service: Service = Provide[Container.service]) -> None:
        ...

FastAPI also does a similar sort of trick, for DI and also request parsing.

https://python-dependency-injector.ets-labs.org/introduction...


django-ninja and fastapi does dep injection, parsing and validation based on annotations.

taichi does ffi with their own dsl, cython with c.

I you haven't tried pydantic or sister projects (django-ninja, fastapi and typer), this is a good place to start. They bring a breath of fresh air and are quite fun to use.


Specifically it's the underlying pydantic that does validation based on annotations

https://pydantic-docs.helpmanual.io/


Indeed.

The dep injection is fastapi and typer code though, and quite tied to it. So it's worth mentioning that somebody is attempting (quite successfully from the look of it) to create a generic lib of dep injection using annotation named DI, inspired by those libs: https://github.com/adriangb/di


I always find it very funny that fastapi has that name when it relies on pydantic that is one of the slowest libraries in that space :D


It's not one of those that you listed, but the @dataclass decorator uses type hints to auto-generate classes and class constructors (__init__ method) for you.

An example:

    @dataclass
    class HackerNewsPost:
        title: str
        author: str
        votes: int = 0
This will generate a constructor that looks like this:

    def __init__(title: str, author: str, votes: int = 0):
        self.title = title
        self.author = author
        self.votes = votes
This is pretty useful, writing __init__ boilerplate has been a common thing in my experience using Python, and it makes code more compact and readable.

It can do some other things too!

https://docs.python.org/3/library/dataclasses.html


For FFI, there is a pure python mode in cython:

  https://cython.readthedocs.io/en/latest/src/tutorial/external.html


I used them at runtime to define the types for my (absolutely stupid) library that takes a Python function and replaces its contents with a C call.

You define a Python function interface but populate it with a string of C code.


Wait, so like this?

    def add(x: int, y: int) -> int:
        """ // c code
            int x, y
            return x + y
        """
And it compiles it and turns it into a C extension?

That's...horrifying yet amazing.


That might be a worthwhile addition to the suggestion at https://github.com/faster-cpython/ideas/issues/453


Combined with the cog (https://nedbatchelder.com/code/cog) to have the c declaration in a proper separate c file, but included in the docstring, you could have the best of both worlds.


That's a neat hack!


There's a library for simulating the Excel calculation engine in Python. It uses annotations to hint functions, but according to Excel's type system, not Python's. Then at runtime, those hints are used to do conversion and promotion based on how Excel does it, so you can do e.g. the equivalent of "1" + 1 and get 2.

It's either xlcalculator or pycel, one of the two. I forgot which one does it that way.



Things like pydantic and fastapi where the type annotations are used for run time argument validation and interface generation.


Does this still work with Python 3.10 changes removing runtime evaluation of type annotations? I seem to recall this screwed me when I was writing something for runtime usage of types.


They postponed that change.

It remained enabled with a future and while it kinda works, it doesn't work in all cases. Non top level definitions can never be retrieved basically.


There was a heated debate because it broke things at the time, but now it works, yes.


Oh it looks like they actually pushed back the PEP 563 changes..

From this thread [0] it does not look open and shut that it will work once these changes go into effect.

[0]: https://github.com/pydantic/pydantic/issues/2678


we still don't know what's going to happen with type hints in future though, but I'm sure things won't break as they might have broken if they changed the default behaviour


Creating argument parsers for CLIs: https://pypi.org/project/argtyped/

I've seen similar (in-house) to generate HTML forms also.


I've created strawberry graphql, it uses type hints to generate GraphQL schemas


Being stabbed with a knife could kill you.

Could.


Yes, and very few people use that because most users can't tell an app from a website, spell URL correctly or tell you what "" does in google.

When I need those features I use the operators directly in the search field anyway.

The single omniscient search field is an amazing interface, it's incredible at what it does, which is understanding what our idiodic human brain is attempting to express with sausage fingers a monday morning.


> spell URL correctly

That's impossiboe by design. There are different cuaracters that look identical, foreign alphabets and special characters. Then there are GUids and queries in url


The whole reason SV exploded was that people were doing things instead of waiting for the theory to show it can work.

That's how software has innovated for 30 years: by practice.

Giving a price to an economist, the opposite of somebody practicing and producing, is a signal something is going wrong.


did you read the article? They showed that the economists are designing experiments that lead to new features.


Implicitly distrusting the beancounters is not a bad thing.


Hey, accountants aren't economists..


Indeed, accountant predictions usually end up being true.


There are plenty of economists who do experimental and applied work.


Hiring economists into tech has also been going on for many years at this point. I roomed with a PhD candidate years ago who described fairly established hiring pipelines from Economics PhD programs into industry.


Condoms effectivement is 98%: https://www.nhs.uk/conditions/contraception/male-condoms/

If you have sex twice a week (which for a young couple is very conservative), after a year, you've reach 100 attempts already.

You then better hope the two patners agree on wether or not keeping the baby.


It's 98% for the condom itself, but if you couple it with the fact that the 2% failure rate has to correspond with an ejaculation in an ovulating female's vagina, the actual effectiveness is much higher.


That's not accurate (if it were, we wouldn't have efficacy rates for coitus interruptus and the rhythm method that this can be directly compared to, which we do); but the rate is per year, not per act. From the link:

>When used correctly every time you have sex, male condoms are 98% effective. This means 2 out of 100 people will become pregnant in 1 year when male condoms are used as contraception.

On the other hand, over 20 years, that translates to an efficacy rate of only 67%.


And that's "if used correctly".

Now add passion, alcohol, nails, wrong lubricants, and ignorance for a much worse rate.


Ah, tracking the entire population even in the highest mountain and the deepest desert.

And all that to protect your love ones, of course.

People apparently forgot all about PRISM already. That didn't take long.


Its amazing to me how easily people are willing to give Apple their data compared to Google, Facebook or Microsoft. Specially looking at how Apple was to willing to put its servers in countries that want control of the data. I think people seem to forget the privacy fight was not about privacy from advertisers but from government over reach. People are looking at Google for building skynet but Apple seems to be successfully building it and people are enthusiastically adopting it.


Apple has a really strong track record of resisting Government intrusion, within the bounds of the law, not selling customer data to third parties, and holding app developers to account for the privacy of their apps. The others have business models based entirely on selling user data.

The contentious element is the "within the bounds of the law" bit. In the US and Europe that means a lot, because Apple can use the courts to block government overreach and they have done so. In China they can't do that, so they don't just as nobody else operating within China can.

Google does deserve credit for refusing to operate their search services within China, while Apple and many other companies decided they were willing to do business there on Chinese government terms.


Apple is much better at marketting than Google, Facebook or Microsoft.


I'm genuinely getting pretty annoyed by this increasingly prevalent style of know-it-all neo-ludditism that manifests as middlebrow, pithy dismissals of entire technologies with obvious benefits.

If you have a viewpoint on the relative risks of these technologies, the I genuinely wish you'd use your time to talk productively about what you think the risks are to help others make an informed choice – instead of sarcastically assuming that anybody who doesn't have the exact same set of priorities as you is a fucking idiot. It's making the quality of discussion on this site totally unbearable.


Well, asbestos has obvious benefits. It's an amazing, cheap way to insulate things, and it's very resistant to fire.

We knew abestos was dangerous even before the WW2, and kept using it because it was so convenient.

That's the thing about know-it-all neo-ludditism pithy dismissals. They started 30 years ago witha much more soft tone. But since not only people ignored the warnings, but eventually even came to insult the people performing said warning (even after the warning proved to be true), the same people turned kinda sarcarstics.

Poor you to have to read a rational argument in a comment using history and logic to underline our societies shit where they eat and ignore the asymetry of risk.

Sacarstic people are mean and don't understand how to have quality discussions. They should always stay perfectly calm and neutral while they feel like half of the population is setting us up for troubles.


>Poor you to have to read a rational argument in a comment using history and logic

Your comment above didn't actually contain any such thing. It contained a vestigial semblance of them too trivialised by vitriol to land a persuasive point.

>Sacarstic people are mean and don't understand how to have quality discussions.

Not always for sure, but yes that's often the case.


Oh but this comment is part of a thread. Because comments are in a context. Like this one, from 6 hours ago:

https://news.ycombinator.com/item?id=32763171


You should read up on how AirTags work; Apple does not ever know the location of any person or their stuff. Good read: https://support.apple.com/en-gb/guide/security/sec6cbc80fd0/...


There are articles/white papers available, showing Find My info is only visible to people you authorize it to.


Sure.

Because 3 letters agencies never, ever had backdoors in popular systems. It's not like the US had an illegal massive secret cabale dedicated to mass spying on its own population after all.

Luckily, Apple plateforms are notoriously open so it will be easy to check. It's great that we don't have to take their word for it after they lied about not being part of any PRISM-like program.

Anyways, all that doesn't matter much. Why would it be a problem when the economy, climate, international politics and the democracy are so stable these days? I can't see any reason why history would repeat and powerful entities would abuse any power they get.

Somebody who thinks like that would be a crazy tin hat conspirationist, and not at all a concerned citizen.

No, only the part of the population ready to spend hundred of dollars on an upgrade to get copy/paste must be capable of rational thinking. Anybody else is biased.


which changes nothing, they're free to do whatever they want in actual code.

There is also no source code or even audit by 3rd parties (that are not US government related)


> And all that to protect your love ones, of course.

And for your own privacy!


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

Search: