« first day (3938 days earlier)      last day (995 days later) » 

12:15 AM
Is the code monolithic or separated into classes? If classes, have you added simple unit tests so you can run tests after making substantial changes?
 
 
4 hours later…
4:24 AM
hi there
 
4:43 AM
hi
 
 
2 hours later…
6:14 AM
Fixed counting bug, gotta love me those git messages xD
 
cbg
One guy I used to work with on projects would commit with "update".
 
6:30 AM
haha rough
kevins pagliacci joke is understarred :D
 
7:24 AM
Hello guys
 
I use pyrasite and guppy library to statistics the total memory of the python process, why the total used memory is not equal the result of the system command like top, ps?
 
Is it massively different?
 
What exactly are you lookin at in guppy?
In general, memory is a lot more complicated than "things my program stores".
 
I think MM should take this one. "So, how much memory is the LHC consuming?" All of your memories am mine
 
The guppy docs suggest it is used to inspect the actively used heap. Your program will have some overhead for overallocated heap and the stack, plus memory shared with other applications.
 
7:34 AM
yes, result of guppy is about 2.3G, while it is used 3.4G in top
 
@roganjosh All your compute are belong to us.
 
is there any objects that guppy can't monitor?
 
@baozilaji Are you checking RSS or VSZ in top/ps?
 
RSS is 3.4G
 
@baozilaji There is memory that isn't actively used for the heap.
 
7:41 AM
how can i find out which objects that isn't actively?
 
Sorry, I didn't get that.
Do you know roughly what stack and heap are?
Might be relevant since it gives a rough outline on the difference of RSS, heap and stack: stackoverflow.com/questions/17381502/…
 
I'm not clearly about that. I'm checking that is the process have memory leak.
 
"Memory leak" as in "memory that cannot be freed" or as in "memory that I'm using needlessly"?
 
memory that I'm using needlessly
I doubt that there maybe some objects is considered to be deleted but not.
 
Now you're talking about garbage collection, and it's very rare you need to think about that in Python (if ever). MisterMiyagi has already given you some suggestions on why the memory figures might be different
 
7:51 AM
Hm, these situations are tricky. In my experience it's not worth drilling down to the actual memory usage, since the important information will drown in noise. Consider to view the issue not as as one of "owning things" but as one of "releasing things" – you want to look at function calls, not object size.
Oh, right – if you think your program leaks memory because the heap is smaller than the RSS, that's very, very, very, very likely a red herring.
 
@MisterMiyagi ok thanks a lot.
 
8:49 AM
大家好
 
@jett english please
 
English is poor,No mother tongue friend here?
 
@jett while I'm happy for greetings in a language you might share with another user, please keep to English for actual discussions
 
emmm,Fine, I try use english to talk here
 
We will try and work with attempts at English where we can
 
8:58 AM
Yes,I know
 
9:31 AM
It got raised that my library beatroute at work should also print ASCII art of beetroots on everything it does. I think that's overkill :P but I'm trying to think of a nice way to get an Easter egg of from beatroute import beetroot. It's no fun if it's not animated, but I'm not sure what might be a reasonable way to go about it in a terminal that can't launch any windows (i.e. tkinter windows are out). Any ideas?
I'm off work today, so I'm focussed on the important things
 
@roganjosh Did you ever build PyPy from scratch?
 
a lazy way would be to just use print("\033c") at every loop to clear the terminal and just print a series of ascii arts, I guess that would animate
 
@jett for the record it's official Stack Overflow pokicy to use English in chat. Thanks for understanding.
 
I did not, MM
 
like a flipbook but only in the terminal
 
9:37 AM
There is a point that beatroute goes quiet when it first has to download a CSV of postcodes, so maybe I could have some threaded animation there
 
I'm sure tqdm has a feature for that too :P
 
What about finding a route that looks like a beetroot?
 
LOL, I've not got that much time on my hands. Also, I wouldn't be able to embed it in the terminal :(
 
My bad, I thought there was a map involved.
 
I mean, there is, but only in lat/longs. Our platform won't allow for windows so there's no way to get a map displayed (that I know of)
 
9:44 AM
I think ffmpeg has an ascii codec...
 
Indeed, it looks like you could do it with ffmpeg-ascii. Thanks!
 
I've got some code maintenance concerns.... is it "obvious" to people why this one actually works?
class Foo:
    __slots__ = ("__repr__",)
    def __init__(self):
        self.__repr__ = lambda: "Hello World!"

print(Foo())
 
I would say it has __repr__ so it works, but I dont know about __slots__
 
Ah, yes. You can comment out the __slots__ line if it is not obvious why this might not be obvious.
 
@MisterMiyagi I'm on the "why would it not work?" side of Dunning–Kruger
Ah, looking up dunders on class, right?
 
9:57 AM
Yep.
 
Then not obvious at all, to me
But I'm also barely aware of slots
 
@AndrasDeak That's where I was 15 minutes ago. :P
 
Pretty much the same boat as me. I wouldn't know what that code was doing just by looking at it
 
__repr__ is defined as an instance variable instead of the class level, that is the only difference I can see
 
@MisterMiyagi Absolutely not
 
10:05 AM
It's big rain outside ~_~
 
@jett take care and avoid the subway
 
 
1 hour later…
11:09 AM
@MisterMiyagi I vote not obvious
 
11:21 AM
any better way to get an abortable sleep in a thread where the parent thread should be able to abort the sleep? This feels kinda dirty
def abortable_sleep(self, sleep_time, interval_to_wake_up=0.02):
    counter = 0
    while self.should_run_thread:
        time.sleep(interval_to_wake_up)
        counter += interval_to_wake_up
        if counter > sleep_time:
            break
 
You could use a Lock
def abortable_sleep(self, sleep_time):
    self._lock.acquire(timeout=sleep_time)
 
just don't forget to release it again. :P
 
Or create a new one
 
I fail to see how this implements an abortable sleep
 
The lock would default to being acquired, so abortable_sleep waits for it to be released.
Releasing the lock (by some other thread) immediately lets abortable_sleep get the lock. Otherwise it waits until the timeout expires.
You could also use an Event, but AFAIK it basically does the same lockdance under the hood.
 
11:50 AM
class Waiter:
    def __init__(self):
        self._lock = threading.Lock()
        self._lock.acquire()

    def sleep(self, duration):
        self._lock.acquire(timeout=duration)

    def wakeup(self):
        self._lock.release()
Actually simpler than I thought. No if lock.acquire(): or anything necessary
 
Are you sure you don't have to reset the lock if sleep acquires it?
Ah, no you don't. It must be acquired anyway.
 
Yeah, it's supposed to be acquired
 
What happens if you wakeup when nothing is sleeping?
Can wakeup do self._lock.acquire(timeout=0) to be sure?
 
The next call to sleep will return immediately. If you do it twice, I think you'll get an exception
@MisterMiyagi I don't think so. That'll just introduce a race condition where you're not sure if sleep will wake up before you re-acquire the lock
 
Yam, I think that would actually be simpler with async. :/
 
12:34 PM
thanks @Aran-Fey the lock solution is really neat :)
 
12:56 PM
Ok, I have following code, which I'm kinda happy with. It little lines of code, but quite some comments. But I still see some potential race condition which I'm not sure how to fix.
brb, gotta go to the sandbox
 
please do
 
Ok now, somehow got tabs mixed in there
 
a pastebin might be a good idea. :P
 
Now what I'm worried about is that both the parent thread and the child thread call release at the same time. Basically what could happen is that the parent wants to interrupt just after checking if the lock is held and the child then just released the lock, thus calling release twice and generating a runtime exception
is there a way to check the lock and release it atomically?
 
1:03 PM
thanks
 
I think it would be better to mint a new lock for every thread.
There seems to be no point in reusing the old one for your case.
 
how does that help with the outlined issue? I don't get it
the parent and child need both access to the same lock so the parent can interrupt the child. Taking a new one after the process finished is a separate issue or am I missing something?
 
Ah. Misunderstood why you want to check the lock.
 
I'm not quite sure what your goal is and reverse engineering the code isn't really helping me figure it out either. AFAICT, you want to wait for 42 seconds before doing some task, and if this is cancelled before the 42 seconds have passed, you don't do said task. But I have no clue what all that other code (outside of potentially_wait_and_do_stuff) is for
 
Hm, no. I'm still somewhat stumped why the single lock is re-used at all. If it's not used both to wakeup the old thread and check on the new thread, the race condition seems to be gone.
There's just no need for the thread to self.lock.release() if the lock is just thrown away.
 
1:12 PM
parent checks some data source periodically, on some change it dispatches child to do something after maybe waiting. While the child waits the parent still checks data source, when the data changes again it interrupts the child and does the same thing the child was supposed to do again with the new data
 
Ah, that helps
 
@MisterMiyagi and I defined the lock inside or outside the thread? If inside, how do I call it from outside? If outside it won't be gone when the thread finishes no? Can you show me some code how you mean your suggestion?
 
Why doesn't the child just do its thing after being interrupted?
@Hakaishin You can pass in the lock as an argument. Once it goes out of scope/is replaced it is gone.
 
@MisterMiyagi because it needs to potentially wait again
 
@Hakaishin Why would that be? Right now the parent just wakes up the child, then the child exists and the parent does child task. Why doesn't the child to child task either way?
@Hakaishin "Can you show me some code how you mean your suggestion?" Without the missing bits, not really.
 
1:16 PM
@MisterMiyagi No, the parent after making the old child exit starts a new child with the new data. Not sure where you get that the parent is doing the child task
 
I thought "it interrupts the child and does the same thing the child was supposed to do again with the new data" means the parent does the same thing the child was supposed to do
 
I added two lines, to show what I wrote above. The getting foo from a data source and the canceling of the thread in case foo changed
 
So what happens if 42 seconds pass and the child starts working on its task? Does the parent stop polling for changed data then? If not, and if it finds new data, does it launch a 2nd child thread while the old one is still running?
 
That is actually a very good concern I have not yet thought of. Ups
No it should also then abort the child and start a new one with new data. As long as the child exists and the parent finds new data it should abort the child
hmmm, but yeah, so I need to make not just the sleep abortable but everything. That's gonna be annoying
I wish there was @abortable, which interjects inbetween each line a flag check to stop the thread
Ok I'm going the process route. Since the child doesn't hold any resources and I don't care if it finishes or not once the data changed. I could make it a process and then simply terminate that on data change. No need for locks and no race conditions
Or could there be a problem with regularely terminating a process in the middle of execution if it doesn't have any file handles or other resources. Do stuff is just a http request
 
you might have pinged some one named abortable :D
 
1:27 PM
hahahah, that would be a weird name
 
@python_user <-- party-pooper. Tags in chat expire after (IIRC) 14 days. So if that person hasn't been around in the last 14 days; tough luck
 
huh, did not know that
 
I apparently failed to think about the fact that your name would appear in my message so my arrow wouldn't point to my name :P
 
laurel, I was wondering why
 
@roganjosh so are chat names here different things tha SO names? Can I change my chat name here to something else than my SO name?
 
1:35 PM
They're not different (somewhere in the DB they are, because I know myself that names can get out-of-sync). But they become unpingable in chat after a certain amount of time
Names are not unique on SO, so I guess they need to know the user ID that you're really trying to ping
 
@roganjosh So what if two people with the same name end up in chat together?
 
Well, it would take 3 people for a proper Mephistopheles summoning. Not sure about two.
 
Seems like this should be tested.
 
Ok lol the new version is so much simpler, still interesting excursion into locks
p = None
while application_is_running():
    foo = get_foo()
    if p is not None and p.is_alive():
        if foo_changed_compared_to_last_iteration:
            p.terminate()
            p = multiprocess.Process(target=self.potentially_wait_and_do_stuff, args=(foo,), name="potentially_wait_and_do_stuff", daemon=True)
            p.start()
    else:
        p = multiprocess.Process(target=self.potentially_wait_and_do_stuff, args=(foo,), name="potentially_wait_and_do_stuff", daemon=True)
        p.start()
 
 
2 hours later…
3:18 PM
just curious - is anyone here participating in the europython2021 conference?
 
3:50 PM
@toonarmycaptain both get pinged. You can even use a prefix of a given name, and every user who matches will be pinged, I think.
@python_user Pings do indeed time out after 14 days (with the exception of directed replies), and the specific users who can be pinged are at chat.stackoverflow.com/rooms/pingable/6
whoops, it's 7 days, it seems meta.stackexchange.com/a/321653/313143
 
Give me a ping, Vasili. One ping only, please.
 
4:16 PM
Just curious anyone have experience with Napalm here?
 
@JoshZhang Just ask your question. If someone feels they have enough expertise to answer, they will.
 
Fair enough!
When committing commands with Napalm, even if the device doesn't accept a specific line, napalm doesn't seem to return an error and just pushes through.
Really dumb behavior. Example would be pushing a config to an interface, it would accept description but not switchport mode but ultimately when you commit the config Napalm doesn't throw an error.
 
4:38 PM
"Just curious anyone have experience with Napalm here?" is one hell of an opener
I think we need a bit more context. Can you reduce this to an MCVE?
 
okay.. not the napalm i was thinking of
 
 
1 hour later…
5:46 PM
Ugh. I just have to ask: Does anyone have good experience using pyproject.toml for tooling configuration?
I've just wasted half an hour because MyPy claims they parse it but actually they don't.
 
I have no experience whatsoever. I acknowledge that this is not useful information for you.
 
The only thing I tried to use it for is tox, but back then their support for pyproject.toml was a hack at best - you essentially had to include your tox.ini as one massive string. To nobody's surprise, I ended up not doing that. Not sure if the situation has improved since then
 
@Kevin It's useful to know other people don't jump from cliffs.
 
I am the single constant in a world gone mad
 
6:18 PM
@roganjosh honestly, was hoping to spur some discussion with someone who also uses Napalm, and get someone else's opinions on it.
 
@AndrasDeak huh interesting
@And did this ping you?
 
@JoshZhang That isn't how we try run the chat room (SO employee or not). If you have a question then we encourage it to be asked directly and people will chip in if they can help
 
6:37 PM
@toonarmycaptain yes
Not sure if it would also make a sound, maybe not. I don't have auditory pings enabled.
 
7:32 PM
hey!
is it always the case that class specific statements only run once?

class A:
    a = []
    print(a)
b = A()
c = A()
a only gets printed after b is instanciated.
 
No, a gets printed when the class A is created. Has absolutely nothing to do with instantiating the class.
 
okay, thanks!
 
So yes, code in classes is only executed once. Just like all other code, except for code in functions.
 
Heraclitus says you can't step twice into the same function
 
@Luyw A class body is executed as part of its class statements, similar to how an if body is executed as part of its if statement.
 
7:35 PM
I don't know who Heraclitus is but he sounds like he was way ahead of his time
 
He was Herakleitos in disguise
 
Wikipedia claims Heraclitus was involved in processism. That's basically what we do, right?
Folks had some really good cabbages back then...
 
But then the Fire Nation attacked
 
 
3 hours later…

« first day (3938 days earlier)      last day (995 days later) »