« first day (4229 days earlier)      last day (713 days later) » 

3:05 AM
https://stackoverflow.com/questions/72245234/why-does-default-attribute-not-work-in-the-init-method-of-my-class

Ever notice how the "I typo'd a dunder method name" questions are *almost always* about `__init__`, and it's *almost always* mistyped as either `_init_` or `__int__`? I assume the first case is genuine misunderstanding due to bad typesetting in tutorials; TIL there's an actual bias towards the second because of IDE auto-complete.
(wait, why didn't that get markdown'd?)
(I guess the __int__ typo also evades IDE warnings about a method name that starts with __ but doesn't match a known meaningful dunder)
 
3:46 AM
@KarlKnechtel Mult-line messages disable Markdown. That's (mostly) so code doesn't get Markdown'd.
 
4:00 AM
@KarlKnechtel Right. It's tricky because __int__ is a real dunder: docs.python.org/3/reference/datamodel.html#object.__int__
 
 
9 hours later…
12:35 PM
I have a weird async problem that I can't figure out, but it started popping up when I unrolled an async for loop like this:
async for x in foo():
    print(x)
Into this:
i = foo().__aiter__()
anext = i.__anext__

while True:
    try:
        print(await anext())
    except StopAsyncIteration:
        break
Is there something wrong with that?
 
12:54 PM
Never mind, I just managed to reproduce the bug with an async for
 
1:38 PM
Is there a way to plot energy levels using matplotlib as in this figure
https://ibb.co/NFWGkJV
 
I'm stuck, if you could help that's a pleasure
 
Well, you just have to draw it
first draw the dashed lines, then the coloured bars
 
I mean I have the data for each nuclide
 
I'd probably write a helper function for the coloured bars, which plots one column (one method) in a given colour
@EnthusiastiC having the data you want to plot is a good start
 
1:41 PM
I used to draw each separately and that's become chaotic
 
yeah, you need to identify the repeating bits and put that in a function you keep calling
but you'll also need to define how those dashed lines go from method to method, because that's ambiguous a priori
for instance between p=2 and p=3 you have a crossover at high energies; that's something that has to be an input into the dashed line drawing
 
I don't need the dashed lines though
and...
 
instead of p=2 and the likes I need nuclei labels such as, Sn130, Sn132, ...
each stack of bars represent one nuclide
 
that's irrelevant from a data visualization standpoint
 
1:45 PM
The relevance is
comparing theoretical computed states (bars) with experimental data hence (two different colors to differentiate them are needed)
 
you can use matplotlib's default 'C0' (blue) and 'C1' (orange) colours and colorblind people will be able to tell the difference
 
at the end one should get the same plot, except for bars are doubled (computed and experimental values) and labels represent nuclide names.
 
or if the theoretical results are good enough you could plot them both in the same column, one with solid and the other with a dashed line
@EnthusiastiC "same plot": same as what?
 
@AndrasDeak--СлаваУкраїні ibb.co/NFWGkJV
 
OK, so "same as the one you linked earlier". But you don't want that, you don't want dashed lines for instance. So "same plot" is not exactly true.
I'm not trying to be difficult, I'm just trying to cut through the ambiguity because it's hard to tell you what to do when I can't be sure I understand your requirements.
 
1:51 PM
I see. no problem so far
 
excellent
So you want the "same plot", but also you want theory and experiment to be present for any given nuclide. Does this mean you just have 2*n columns for n nuclides, with expt./theory alternating in each column? Or do you have something else in mind?
 
ok wait.. I will edit the previous image for more enhanced explanation
 
it might be easier to draw a mock-up by hand at this point
 
I didn't draw it precisely.
https://ibb.co/X4mbL6t
green and red should be black instead.
without dashed lines
 
2:09 PM
I don't recommend doing that: in the best case of full overlap your visualization becomes ambiguous
 
oh really
 
2:29 PM
Hi, I'm having trouble with a very simple Python program.
 
2:49 PM
Aug 26, 2021 at 22:08, by roganjosh
@rb3652 please see our room rules, particularly in regards to waiting 48 hours before bringing questions here
we also discourage posting code as images
 
 
2 hours later…
4:52 PM
who'd have guessed that getting lat/lon the wrong way around would lead to interesting map placing :p
 
That was one thing I meant to caveat for OSRM when you were asking about driving distance. I'll take that as a prompt just in case - the URL route requires lon,lat pairs, but it will happily snap-to-grid anywhere on the globe even when it doesn't have the underlying map profile. It'll just return whatever geographical boundary it hit on your map profile... somewhat insidious
 
oh okay... I'll try to remember that
in this case it's my yam up anyway
 
Given the 6k views you'd be in good company if you made that mistake :P
 
lmao.... have another view
 
Do you listen to any of the digitally-produced music Jon? Over time from listening while I work, my youtube playlists have become dominated with the stuff e.g. this that came on. I know you listen to a huge spectrum of music, just curious whether you listen to this kind of stuff
Once the playlists start, they're seemingly endless. There's a whole load of people making this stuff and actually I think the production is pretty good since I don't think a single instrument gets touched during production at all
Although the technical aspects of the music are often lacking (more bombast and less intricacy) but then Einaudi made, and continues to make, a fortune from that kind of thing. Still, good coding music for me :)
 
5:11 PM
Can't say I do mate... not something I look for anyway
that one you linked does sounds familiar though... can't quite place it through
 
I don't think it's featured in anything, but could be wrong. Though that might be the vibe that's common with this kind of genre in general because it's somewhat formulaic
In any case, I was just curious :) I find music with lyrics distracting if I'm trying to really concentrate, and the same with classical music too. This kinda fits into a happy medium category that doesn't occupy a brain thread
 
might think of some music later that meets those categories... right now though... need to fix my yam up and get something ready :p speak soon
 
 
2 hours later…
7:15 PM
On 3.5 concurrent.futures.ThreadPoolExecutor(max_workers=None) will default to number of CPUs times 5. Currently based on os.cpu_count() I have 12 CPUs so using the old default value I would have 60 threads. As of 3.8 the default formula was changed to min(32, os.cpu_count() + 4) so I would have 16 threads. Currently my application has a value of max_workers=5 but i'm wondering if it will have a benefit to increase this number? I don't see much information on how to optimize this
 
I could be wrong, because I don't know anything about parallel computing, but I think most people don't know and/or don't care to optimize that. As far as I can tell, standard procedure is to pull a random number out of a hat. If someone's feeling fancy, they might perform a basic benchmark called "Which number works best on my PC?"
 
@Aran-Fey the default is usually number of physical cores
so on a 4x2 system (with hyperthreading) you often get 4 (other times 8) as default
5 is somewhat surprising but I've never used concurrent.futures. Also: 3.5???
 
Right, but I mean if someone doesn't leave it at the default
 
ah, sorry, threadpoolexecutor
In that case I wouldn't expect anything specific. I had processes in mind.
@Pherdindy why did you post a screenshot of a webpage that you can just link to? :'(
 
Was thinking it would be easier than to let you guys search it lol
 
7:25 PM
Yes, link to it
every entry in the python docs has an anchor
 
Right will take note hah
 
you already have the yamming URL
 
Anyway, I don't think there's much you can do except go ahead and try out a bunch of different settings. The optimal choice will greatly depend on what kind of work the threads are doing
 
Yeah, just try if it helps
probably also depends on the number of tasks etc.
 
I see thanks still quite new to this parallel processing stuff came across some answers by mister miyagi. It looks like these involve a lot of trial and error generally
 
7:34 PM
@Aran-Fey for what it's worth if I understand correctly ThreadPoolExecutor is still subject to the GIL, in which case parallelism doesn't apply (only concurrency)
 
Oh, it's true, I forgot this requirement.
Sorry
 
I did read GIL a bit and it seems like concurrent.futures.ThreadPoolExecutor() is not the one I need since the code can only run a single thread at a time
I guess asyncio is the solution
 
It depends what you're trying to do
I'm pretty sure that asyncio is still bound by the GIL, it just gives you set breakpoints to yield control to another thread
 
@Pherdindy nope
asyncio is similar functionality to threading. You want multiprocessing, i.e. concurrent.futures.ProcessPoolExecutor
In which case we come back to my earlier remarks. You probably want (at most!) as many workers as you have physical cores.
 
I haven't been in the room much over the last few days. If you're trying to do something CPU-bound then threading isn't the answer (async or not). If you're trying to do something with e.g. web servers, then you probably don't need to be too concerned about the GIL and a small-ish number of threads can do a decent amount of work
 
7:43 PM
I don't think they've specified what they are working on, this might be the first appearance of this problem
 
:/ Unless the problem is described @Pherdindy then this is basically an exercise in futility to try advise you
 
Here's a handy flowchart: You need lots of CPU power? Use multiprocessing. Otherwise, use threads or asyncio.
 
then again I've also been busy
@roganjosh technically they haven't asked for advice
 
"Currently my application has a value of max_workers=5 but i'm wondering if it will have a benefit to increase this number?"
 
I'm trying to speed up the requests. The tutorial I came across used asyncio. I believe it was running the requests in parallel and it had the event loop to see which was completed
 
7:45 PM
You mean outgoing requests to some service?
 
Yes i'm making a request but if I use the requests module solely it's too slow
 
If you're talking about HTTP requests then yes, the number of workers will affect the speed of your program and more workers will speed things up... until a point
 
Yeap http requests it did go a bit faster but would still take ages since it's not really doing it in parallel
 
It is doing it in parallel for all you care
The burden of processing the request isn't on you - it's on the service. Your workers are mostly sat waiting for a reply
 
@roganjosh plus throttling. Pherdindy has had unusual approaches to web services before.
 
7:50 PM
Again, though, maybe you have complicated callbacks you're running on the request response, or as Andras says, you might get throttled. This still feels very vague to me as a description of what you're trying to do
 
8:02 PM
I have been using Python for a long time (Since 3.6) and made quite a few modules and lifesavers with it. However I have always struggled with packing. Would you say that packaging a python module is relatively easy?
 
@SethEdwards nope
packaging is one of the major pain points of Python
 
Is this strictly about packaging or also about the import system in general? If you already understand imports, packaging is fairly easy
Then again, it's not easy to figure out. Lots of outdated old information on the internet...
 
Do we also include building extension modules and dependencies and stuff in "packaging"?
 
If you're asking me then yes (:
 
Yeah, that's what I'd think too. Definitely not "fairly easy" then.
 
8:05 PM
I can pack, but after I get all of that mess to pypi, and I try to rest my package. The module is just not there.
 
that sounds like a more specific issue
wasn't there a sandbox part of pypi where you can test the workflow?
 
test.pypi.org
 
Right thinking about it there can be lots of reasons why it is slow going to do some testing first
 
8:19 PM
@Aran-Fey Yeah i have tried that url, after hours of fussing with twine,pypi and pulling my hair out. I don't think it's worth it to package stuff. It's easier just to inject them with all the other modules. or import them into the same directory as your project.!
 
@SethEdwards note that you don't have to put it on pypi in order to install locally into a virtualenv
you can also have e.g. a private git repo where you install from
 
Let's not overcomplicate: You can just install the project directory with pip install .
 
yes, that's the "install locally" case
 
Why could it not have just been a json file. Life would be so much easier if it was a json file.
 
But one advantage of pypi would be that you don't have to navigate to where the source is when you want to install into yet another env. Speaking from personal experience. (Which is why I jumped to a private git repo.)
 
8:24 PM
I mean, it's just a toml file. Where's the problem? How would json be better?
 
the .whl files, I guess they really wanted to re-invent the wheel.
 
You don't really need to care about those
Here's an idea: Maybe you should just ask us how to do it? Would certainly be more productive than lamenting all your perceived shortcomings of the system
 
Not to mention python's official tutorial isn't much of a tutorial.
I find it sad how people think python's bad because it's interpreted. It's no different than C running on windows, Windows is going to throttle it because Windows is Windows and Bill Gates is a big ol box of secrets.
 
Do you know about the micropython project?
 
8:34 PM
Really equal than C running on windows?
 
@SethEdwards in passing
"Python is <thing> because it's interpreted" will always be wrong because Python is also compiled.
 
and are you sure it makes a difference running on Windows or Linux?
Yeah, and Python is compiled as Andras correctly said
 
They never said that linux doesn't throttle it.
 
Yeah, but how much is throttled?
 
There's a consistent caveat on benchmarks that they won't represent general workloads but benchmarksgame-team.pages.debian.net/benchmarksgame/program/… is an eye-opener. Is that even python?
 
8:42 PM
@Marco I'll do you one better: what is throttled?
 
@roganjosh I think that is CPython, no?
 
@Marco It's running in Cpython, with the ctype interface and Perl's engine for regex
 
Andras: I did not understand
 
@Marco It is not, itself, CPython, though
 
8:46 PM
C runs much faster than Python, right? I just said that. I think we all agree on that (it seems to me that except Seth)
Yeah, Roganjosh
 
@Marco I agree it runs faster than python
 
"I find it sad how people think python's bad because it's interpreted. It's no different than C running on windows (...)"
 
Yes, Technically
 
Firstly, it is not interpreted. And you mean something else, not about the speed of execution?
 
All I am saying is that people shouldn't hate python because it's interpreted.
 
8:51 PM
But Python is not ONLY interpreted
Correcting myself
 
Excatly. If I am not mistaken all base modules and any installed compiled modules are compiled.
 
I can't say.
What do you mean by "It's no different than C running on windows"? About speed of execution?
 
I don't think there's any broader point to be made here unless you both know the details of how Python works under the covers. Suffice to say that I think Seth only made an observational remark and it can be taken as such
 
I haven't gone very far into the nitty girtty. But I have a general idea of how it works.
 
Roganjosh, this is true? "It's no different than C running on windows"
 
8:57 PM
No, it isn't true
 
Oh ok, that makes me relieved
Just wanted to hear that, thanks.
 
I stand corrected.
 
Nice
 
Honestly python should take something from it micro brother (micropython). Micropython has a @micropython.native which runs the code under it faster than normal (my guess is that it compiles the function and runs it instead of interpreting it). That would help loads.
 
micropython only supports a subset of Python, not unlike Cython.
 
9:01 PM
This is fundamentally different to Pypy, Cython, numba, pythran and a whole C interface of endless possibility and other ways of speeding up the code?
 
optimising the general parts i the tricky task.
 
@MisterMiyagi not with that attitude
 
@roganjosh I definitely don't think so
If you have to choose one of these options, which is the fastest? Or depends on the case?
 
PSA: Starring comments is for stuff that is generally useful to others in the room. Please don't just star stuff to say thanks
@Marco It depends on the case and is an exercise for the reader
 
"Cute fluffy animals are cool, okay!?" [sopython](https://sopython.com/chatroom)
I don't get it.
 
9:14 PM
Occasionally people post pictures of baby animals
It's humour
 
Well then...
How does one do that
 
It is not a request or invitation to post pictures of animals. I'm not sure why you would think it was. They're used occasionally to try diffuse difficult discussions
 
Oh thanks, well then (insert picture of fluffy cat).
 
9:56 PM
@roganjosh Nice, ok.
 
10:26 PM
@AndrasDeak--СлаваУкраїні wouldn't it be important if it were written here (python.org/doc/essays/blurb) that Python is also compiled?
 
Well it does mention compilation
> Since there is no compilation step, the edit-test-debug cycle is incredibly fast.
...well...
 
It's also compiled, right?
 
yes, but that doesn't tell people anything, really
 
Sorry?
 
The thing about "regular" compiled languages is that compilers can make very heavy optimizations, which is what Python doesn't do. So even though it's technically compiled that doesn't make it any faster, probably because it only compiles to bytecode that's still executed by a very high-level interpreter.
 
10:30 PM
the docs mention something about that
 
in the general case there are very few optimizations you can do, because even something trivial like foo = list(bar) can do anything if list is changed to mean something different from the built-in name
 
Right, I think I got it, Andras. But, if it's not so important to Python website mention it, why in your argument did you comment that it's also compiled, as if it's something relevantly positive?
 
This is why all the "make python faster" alternatives present a trade-off: restricted functionality to pay for performance improvements.
@Marco because when I see bad arguments being made based on technically wrong premises I like to be technically correct
 
Right
 
@AndrasDeak--СлаваУкраїні well, it's certainly faster than if it had to parse the source each time during execution, but it doesn't make it comparable to non-dynamic languages
 
10:36 PM
Finally: does the fact that Python is also compiled make it faster, compared to if it were strictly interpreted only?
 
But comparisons can be tricky because MATLAB for instance is a dynamic language, but it uses arrays for everything which allows it to have really powerful JIT compilation
 
At what version do you think that python started climbing up the ranks in popularity?
In my opinion 2.7 seems to be where it picked up.
Google trends also show that July 2013 python started gaining more searches
 
I started with 3.5 so it must have been then
 
Yes, it's faster. If it wasn't, python wouldn't do it
 
10:52 PM
@AndrasDeak--СлаваУкраїні I just realized that you had written that the fact that it also compiles doesn't make it any faster, so you meant to just be strictly technical in saying that it also compiles.
Aran-Fey: Whoa!! Another opinion, thanks, that makes perfect sense.
Aran-Fey: Python does, in terms of compilation, something like Java does (compile to bytecode), right?
 
11:50 PM
Yes, python has bytecode. You can see it yourself if you use the dis module.
 
Nice, thanks.
 
>>> import dis
>>> dis.dis("a + b - c()")
  1           0 LOAD_NAME                0 (a)
              2 LOAD_NAME                1 (b)
              4 BINARY_ADD
              6 LOAD_NAME                2 (c)
              8 CALL_FUNCTION            0
             10 BINARY_SUBTRACT
             12 RETURN_VALUE
For example
 
Cool
 
Python does do a little bit of optimization to its bytecode. For example, arithmetic on numeric literals is precalculated at compile time, so 2 + 2 is effectively identical to 4. Not going to break any speed records, but points for trying
 
Interesting
 

« first day (4229 days earlier)      last day (713 days later) »