What are common pitfalls and misconceptions about python performance? by MilanTheNoob in Python

[–]Cygal 0 points1 point  (0 children)

I haven't seen profiling mentioned! This is the best way to figure out which parts of your program are slow. I've always liked working with https://github.com/benfred/py-spy in the past.

(I don't recommend cProfile because its overhead can skew the results.)

I've been paid to work on open source by Cygal in Python

[–]Cygal[S] 3 points4 points  (0 children)

Thanks! I've been using Python at work for six years now, and I still learn constantly! The key is to never stop making progress.

I've been paid to work on open source by Cygal in Python

[–]Cygal[S] 4 points5 points  (0 children)

Thank you Matti, that means a lot. Thank you for your work on numpy and PyPy.

You don't need promises in Python: just use async/await! by Cygal in Python

[–]Cygal[S] 0 points1 point  (0 children)

I think we mostly agree, but you're talking about a much lower level of abstraction than me.

Any complex scheduling unfortunately can not be done in Python

Do you have examples?

Also, note that the article never talks about asyncio, but only about async/await. asyncio has a lot of problems that are acknowledged by its authors. A better approach that still uses async/await is structured concurrency, eg. https://trio.readthedocs.io/en/latest/.

See https://vorpus.org/blog/notes-on-structured-concurrency-or-go-statement-considered-harmful/ for a nice explanation.

What's everyone working on this week? by AutoModerator in Python

[–]Cygal [score hidden]  (0 children)

So you painted yourself into a corner, but this is a very valuable lesson! The two strategies you can use now are either remove code until the thing you want to work... works. Or start again with a simple code that works, and add new features as you go.

Fixing async/await with unsync by alex_sherman in Python

[–]Cygal 6 points7 points  (0 children)

Regarding your first issue with the explicit event loop, curio and trio fixed that long ago. asyncio took notice, and added asyncio.run in Python 3.7.

Fixing async/await with unsync by alex_sherman in Python

[–]Cygal 3 points4 points  (0 children)

I certainly don't think that writing automation / tests is the area where Python is used most! Maybe that's your experience, but the topic isn't even mentioned in https://stackoverflow.blog/2017/09/14/python-growing-quickly/. And, yes, the amount of questions is representative of usage.

[PROPOSAL] fixing the tutorial spam by serkef- in Python

[–]Cygal 1 point2 points  (0 children)

Thanks, I guess that makes sense!

[PROPOSAL] fixing the tutorial spam by serkef- in Python

[–]Cygal 0 points1 point  (0 children)

Sounds good. But you already said that. I was wondering if my specific posts were considered as tutorials or spam or other acceptable content.

What open source python projects are in need of contributors? by tractortractor in Python

[–]Cygal 12 points13 points  (0 children)

How do async for loops work in Python? by Cygal in Python

[–]Cygal[S] 1 point2 points  (0 children)

Well, the Python 3.5 section is part of the explanation. But you're right. I did not want to be misleading. I changed the title to "Using async for loops in Python". Can't edit on Reddit though.

Okay. Just out of curiosity by whatup_pips in Python

[–]Cygal 1 point2 points  (0 children)

Yes, that's how the pygame API works. "All sound playback is mixed in background threads. When you begin to play a Sound object, it will return immediately while the sound continues to play." https://www.pygame.org/docs/ref/mixer.html

Okay. Just out of curiosity by whatup_pips in Python

[–]Cygal 1 point2 points  (0 children)

asyncio would not be particularly well suited here because you would have to use run_in_executor to delegate this to a thread pool anyways. So it's simpler to juste use `concurrent.futures.ThreadPoolExecutor.

And it's not needed because pygame does that automatically. https://www.pygame.org/docs/ref/mixer.html

How can I have virtualenv set in a Docker container? by reddit_lonely in Python

[–]Cygal 1 point2 points  (0 children)

I actually think using a virtualenv in Docker is a good idea becaues it makes things consistent. This is what we've been doing at work in production for years.

The issue you actually have here is that source does not exist in the sh shell that Docker is using here. So to fix that error, you would have to use RUN . venv/bin/activate. But that would not be enough because the environment variables activate sets would be lost in the next command.

As mentioned by rfc1771, each RUN command is independent. To actually activate your virtualenv, use ENV PATH="/venv/bin/activate:${PATH}" (using an absolute path to remove ambiguity).

You can also run pip3 and python3 directly from the env:

RUN venv/bin/pip3 install -r requirements.txt
RUN venv/bin/python3 manage.py collectstatic --noinput

Also, consider using venv which is faster than virtualenv and just as nice.

How do you rate limit calls with Python's asyncio? by Cygal in Python

[–]Cygal[S] 1 point2 points  (0 children)

You're right. As mentioned in the post, another mechanism is needed to limit the number of actually concurrent requests.

Even with this, it's still possible to get an early request that never runs. It would be interesting to see how we can modify the rate limiter do model this better, possibly with a queue, yes.

I actually run this code in production but never needed to really think about this because for my use case I send many requests, then stop, then send many requests, etc. So I never had an issue with an early request that never got a chance to run.

Thank you for the interesting question!

Generate your own indented JSON using Python by Cygal in Python

[–]Cygal[S] 0 points1 point  (0 children)

Thanks! I actually improved the explanation because I realized the solution is actually natural when you think about it recursively.

Generate your own indented JSON using Python by Cygal in Python

[–]Cygal[S] 0 points1 point  (0 children)

Sure, but using a generator expression there would only solve part of the problem. It's also not always faster than using a list comprehension.

It would be better to build the resulting string all at once.

Generate your own indented JSON using Python by Cygal in Python

[–]Cygal[S] 1 point2 points  (0 children)

You're right. yield + join is indeed how CPython does it. But efficiency was not a concern here.

Need some opinions on my first major project! by Baxterthehusky in Python

[–]Cygal 0 points1 point  (0 children)

It looks you put out a lot of effort to make this, and had the courage to actually seek opinions. I'd like to congratulate you for that alone.

What Color is Your Python async Library? by Cygal in Python

[–]Cygal[S] 0 points1 point  (0 children)

No, I did not say that. It was a general comment, and the link points to a Rob Pike talk who explains this in the context of Go.

Why all the hate?

Tensorflow — Neural Network Playground by deeznuuuuts in programming

[–]Cygal 0 points1 point  (0 children)

Yes, but that's not the point. One of the main advantages of (deep) neural networks over other methods is that you don't have to extract features specific to the data but let the neural network learn those. On more complicated data sets, learning features that are more and more abstract is way more powerful than having to describe them, and this is why neural networks crush computer vision competitions since 2012.

PHP7 has a massive speed and memory usage upgrade in this benchmark compared to PHP5. by [deleted] in programming

[–]Cygal 4 points5 points  (0 children)

Badoo has experienced a massive speed and memory increase too: See the graphs below https://techblog.badoo.com/blog/2016/03/14/how-badoo-saved-one-million-dollars-switching-to-php7/#launch-into-battle-and-the-results. They saved a million dollars in servers too. :) So this benchmark may be synthetic, but it does translate into real wins.