« first day (4430 days earlier)      last day (739 days later) » 

01:35
This quote.... we thought we had it bad with endofunctors
... to describe the word "cheeseburger". I think I've finally managed to exhaust my brain enough to sleep. Job done.
 
4 hours later…
05:29
I am trying to use copilot as much as possible. Since it uses public code suggestions and I have put my past solutions into github it means it has also learnt from my previous years using my helpers and can suggest how to use them :D
06:22
@AnttiHaapala--СлаваУкраїні People are posting answers on SO that were created using AI. See meta.stackoverflow.com/q/421778/4014959
I guess it's ok, in principle, if they check them before posting. But that kinda requires them to actually understand what the AI has written.
07:01
@PM2Ring yeah, people have been doing this since the last aoc too.
I guess it's ok too as long as they understand it, but most do not try to do that :/ there also this marketing misconception about how copilot work, since it just use natural language to match against the comments inside the code it fetches against your own input (which also happen to be a comment)
it also applies "mutation" to the input to make it as less distinguishable as the original code, but it only does so on a couple stuff, like variable name, etc
I guess we can't stop people using AI to "cheat" on a coding contest.
I don't know about the semantics, but to me it's just grep with natural language support
I am concerned about people mindlessly using AI to answer SO questions. OTOH, there are plenty of rubbish answers that were written with no AI assistance. ;)
I mean, the way they "trained" it was just running it through the repository on github with the most stars, etc
I don't know much about AI code generation, but I get the impression that chatGPT is a bit different to copilot. ChatGPT isn't interactive. You give it input and it gives you back a solution.
07:14
@PM2Ring that's how copilot works.
the prompt is simply the code from the beginning of file to the cursor position + some extra context
Did you see those answers I linked? Unless I'm misunderstanding the OP, the text and code of those answers was entirely written by chatGPT, without human supervision.
@AnttiHaapala--СлаваУкраїні Oh, ok.
basically it is "continue this story"
but it knows how to rewrite expressions etc in whatever scripts it has so it is not exactly like googling :D
 
4 hours later…
11:15
Cabbage all
Coming in to help vampire ^^
If I'm running SQLAlchemy, what would cause all of my processes to suddenly hang at around the same time (but for some reason, not time out).

I managed to gdb one of the processes and work out what the "current" line in the process' stacktrace was - and it was on SELECT call we run regularly to determine if a change in state has occurred (and we need to do something about it).

When I connected to the database manually, it was absolutely fine. I could run the queries and do whatever I wanted without a problem. When I restart the processes, everything runs smoothly again
Any clues where I could look next to determine my next course of action if I encounter it again? (using mariadb (~10.1.44-0+deb9u1), SQLAlchemy ~1.3.8 (I know, I know. My job over the Christmas period is to resolve the dependency hell I have for these legacy systems), Python 3.5.x (again - I'm working on it)
What's the RDBMS?
Mariadb
My money would be on coinkidink as I don't think there's anything intrinsic in SQLA that would cause it. You could exceed the number of concurrent requests, which might get queued and not cleared by the timeout, or there's a fluke request that somehow ties up the CPU and, again, everything gets queued but doesn't time out
CPU was really happy and under-utilised. All the processes were in a "interruptable" sleep state rather than their usual "busywait and pointlessly consume CPU" state
Anecdotally - We use redshift and it can only have 500 concurrent connections. After that, the central cluster will just hang for everyone and I don't think the default timeouts will fire. Also, if you ramp it up to 100% CPU, you get the same effect. I guess it gets its handshake so it doesn't trigger the timeout
11:29
@roganjosh I was willing it put it down to some random coincidence. But within 24 hours I had one unit do it twice, and another unit do it.
Sorry, didn't mean to ping.
However, you can still run queries as admin otherwise you'd never be able to kill anything. So even if the DB is deadlocked in either of those states, you might be fooled if you used a dev console to run another query
If you suspect SQLA then I would have another query ready to fire in the next deadlock situation using the direct bindings to MariaDB in python. Then set that off. That would remove any bias that you might get if you execute a query within MariaDB itself
Basically - this
If you have ~150 sleeping connections then you're pushing your luck and you might spontaneously lock. But you'd still have the root connection to fool you into thinking it was in SQLA because, hey, it's working when you're in the console (or whatever. I've never used MariaDB)
So, right now I'm inclined to think it's not solely on SQLA, since we've had units running with the same version for a number of years and we have never seen the problem before. But it might be our old version fighting with newer versions of mariadb (or something).
Is there anyway "in-band" to detect that this has occurred? In many places, it's okay if we back off from checking the state because the code has to do some work anyway in the meantime before checking again.
I'm currently throwing together a disgusting hack in the meantime (because this is a new and developing issue), but I would much rather do it properly
I'll see if I can find some method to check the number of connections from the MariaDB side in case we've somehow consumed our quota of connections. I would be surprised if we're maxing out though
11:55
It's easily done with a stray context manager
@OldTinfoil I don't use mariadb, but this looks like it might work: stackoverflow.com/questions/63330052/… and stackoverflow.com/questions/6502036/… (the latter isn't strictly for mariadb, but the commands there looks similar...)
(roganjosh might know a better way)
It's my biggest gripe with the DB API. I not only brought our central stack down, but I'd recruited people to help me as "good practice". Once you have a stray conn in a webapp, it'll swamp the cluster very quickly
with some_library.connect('<conn_string>') as conn:
    c = conn.cursor()
    c.execute('something')

print(conn) # Err, this is a problem
Incidentally, the SQLA engine in a context manager does clear up after itself. But the base drivers often don't
@NordineLotfi Okay thanks, if I see that mysql thinks the threads are running, but they're sleeping that'll confirm for sure that I'm on the right trakc
@roganjosh - How would it recover from c.execute('something') if it never returns from that line?
The problem that I was illustrating is actually that conn leaks here; one would expect the context manager to close the connection, but it doesn't, it only closes the cursor. That's how stale/sleeping connections mount up out of no where. So I would look at the stale connections that might be causing other queries to hang before trying to think about how to recover from c.execute()
If you're lucky, the lifetime of the stale connections kills them off at a fast enough rate (maybe after 30 mins of idle time?) that the new stale connections don't exceed the pool
Ah, sorry with you now. My brain is clearly not working today. Thanks for the recommendation and I'll take a look into it
12:07
@OldTinfoil btw, before I forget, is the ascii art on your website a moon over a mountain, or something else? It looks like a brain floating or something
@NordineLotfi If you zoom out to like 30% it's hopefully a bit clearer. It's a picture of the Earth from the Moon :)
:O got you, make sense now
did you make that yourself or using a script? I know there a couples of ascii arts tools on most linux repos
still looks cool either way :D
I used a script - can't remember which one now. I vaguely remember having to posterise the image before putting it into the ascii art creation program.
I see, nice
looks pretty good even when compressed
Cheers though. I felt it's a tiny bit nicer than having my usual "What are you doing here?" page
@NordineLotfi Looks pretty awesome, NGL
This might well be the janky way I am maintaining the connection finally coming and biting me in the arse. I was planning to do it properly in the next minor version bump in our software. Might prioritise that if it's the case. Will also likely reduce the number of spurious DB corruptions we encounter

(I wonder why now, if that's the case)
12:19
If you're already using SQLA for raw queries then I would strong recommend this pattern
from sqlalchemy import create_engine

engine = create_engine('<blah>') # This is not a stale connection. It's lazy

with engine.connect() as conn:
    conn.execte('<something>')

print(conn) # This will fail. It cleaned up after itself
Then just pass the engine around as you wish. It's too easy to forget conn.close() if you use the driver itself. Frustrating design because it only takes 1 mistake :'(
I use the ORM/sessions as well, depending on the nature of the task. If I'm doing like a bulk insert then I definitely use raw SQL executions
But I'll definitely use the above in places where I'm just doing a raw query
@OldTinfoil I vaguely recall I found someone who did something similar (on reddit), but instead of using two telescopes (like on the twitter's link) they used a single one and a cheap camera. They probably used a similar technique, either called "image blending" or "image merging". Here an example: github.com/simon-r/SerialPhotoMerge
@roganjosh Too bad that their API doesn't handle it like with opening/closing files. Most OSes close file handle when they're unused. Even if you forget to use file.close() or don't want to use a context manager to do that, it will inevitably close itself after a certain amount of time (I think) if the related processes (eg: the one that opened the file, etc) are also closed.
12:55
@NordineLotfi I don't retract my statements as often as I should, really. In low-stakes situations, I often stubbornly defend an obviously wrong viewpoint, mostly because I think it's funny
That's fair. I don't always do it either it seems...unless it's high-stakes maybe?
Today I learned that using the Windows API to un-minimize all windows is not a good idea. I think I'll have to reboot...
Dare I ask what happens if you try to un-minimize all windows?
My guess: there are lots of background processes in the average Windows user session, which spawn a window object on bootup, and the window is then immediately {hidden|resized to 0 x 0|minimized|moved offscreen}. Un-minimizing everything may reveal dozens of windows that were never intended to be seen.
In my experience, when I have six windows open and call EnumWindows, I get about a hundred and six results.
The desktop where I unminimized them now looks like this
13:12
"Default IME" -- yep, I often see tons of those in a typical EnumWindows result.
Do you know how I can tell whether a window is an "application window"?
stackoverflow.com/questions/74656281 assuming the simplest reasonable interpretation of what OP wants, do we have a duplicate for this? I know there's something for filtering digit characters in a string, but presumably OP is looking for a contiguous block of digits
@Aran-Fey I was just about to say, if you figure out how to find only "real" windows, let me know because I am very interested
A longstanding mystery (which admittedly I haven't tried very hard to solve)
is "real window" a coherent concept here? What is actually different about the processes creating the ones you don't want?
They don't have taskbar icons, I guess?
13:14
Valid question. I don't have a strong idea of what a "real window" is.
All windows with a taskbar icon are real windows, but not every real window has a taskbar icon. Or at least, not every real window has its own taskbar icon. If I have three Excel windows open, the taskbar still only displays one Excel icon.
vscode
vscode for real projects, geany for small single-file stuff!
I was about to say, I'm surprised Aran use Geany too
Am I the only one who always has 2 IDEs open at the same time?
13:17
Then again, I'm not one to talk, since I switch text editors every so often
@Aran-Fey I do worse, sometimes I have 4 open
usually I end up closing one or the other for various reasons, probably related to mood or something
@Kevin I think I wanted to find windows on Windows that are being currently displayed once, but didn't get around to do it yet (I know how to do it on Linux though).
I expect you can eliminate the majority of "fake" windows by looking for signs that it's not intended to be seen. If the window title is blank, or if it's "Default IME", those are likely fake. If the window has a height and/or width of zero, it's likely fake. If its screen coordinates are ten million pixels to the right of your monitor, it's likely fake.
If I ever find clues, I'll report back I guess
@Kevin probably they have a specific id. just a guess
if you just want the windows listed when you do Alt+Tab, this might work: web.archive.org/web/20160818223021/https://…
My guess is, there's no objective criteria for a "real" vs "fake" window, because Microsoft never intended for anyone to create fake windows. I suspect that every program with a "fake" window has a similar origin story: when the original developer was just beginning to prototype out their program, they copy-pasted an example program from the windows API documentation, which spawns a useless blank window.
The developer got their prototype working, and tried to go back and remove the window creation code... Only to discover that removing the window broke the rest of the program.
I can see those "hidden windows" being useful for debugging sessions and what not. Don't know any other reasons why they would be left there otherwise, but I could imagine there other reasons
Maybe creating a window signals to the OS that the process has permission to allocate other kinds of resources, for example device independent bitmaps. If you tried to allocate a DIB without creating a window, maybe it would simply fail. (baseless speculation level: 95%)
Maybe Microsoft never attempts to address this problem, because there is a way to allocate a DIB without creating a window first. Maybe this feature is poorly documented and 99% of developers never figure out how to do it, but that's not Microsoft's problem.
Theory 2: creating a window does not entitle your process to any special permissions, and it is entirely possible to remove your useless window creation code from your program without hurting anything else. But perhaps it's hard to identify which lines of code are solely for the purpose of creating the window, and which lines are actually doing something important.
Perhaps it requires a moderately strong understanding of the windows API, which you're not likely to have if you created your prototype by copy-pasting examples from the docs.
13:35
I think I found another possible Theory: codeproject.com/Articles/16362/Bring-your-frame-window-a-shadow they might do this to create windows's shadows
at least it's possible on older windows version, don't know about Win10/etc
(None of this is to say that these hypothetical developers are dumb or lazy or didn't do their due diligence -- it's legitimately difficult and time consuming to become proficient with the Windows API. If your prototype is 99% complete and all you need to do is not display your useless window, it's perfectly rational to write one line of code to hide it, rather than spend 100 more hours trying to refactor it out completely)
I'm not at all surprised that "removing the window [could break] the rest of the program" in a way that isn't trivial to fix - considering how GUI frameworks like to handle component hierarchies
the programs' "real" window might have been created as a "child" of the dummy, and the programmer (who was following a tutorial) might not have fully understood how that part works.
"becoming proficient with the Windows API" sounds Sisyphean, considering their commitment to backwards compatibility. (I call it "bend-over-backwards compatibility")
I don't think backwards compatibility is the problem here, but most likely the lack of enough documentation (as usual).
At least on Linux/etc, you can just tell yourself "at least it's open source", so it'll be documented enough in the long run (hopefully), otherwise, the possibility is there. But with Windows (API), you have to depend on either people reverse engineering their API and posting example/solution, or the official Windows docs showing precious information.
In my experience, the Windows API has good "bottom-up" documentation, but not "top-down" documentation. Every method, for example EnumWindows, has its own documentation page, which thoroughly describes its parameters and return values. There will often be an extensive "remarks" section discussing the method's technical minutae. Good bottom-up documentation.
But if you're starting your project with a high-level idea, like "find all real windows", it's going to be difficult to figure out what methods could help with that. You won't even know if the concept you're trying to describe is a real thing.
everything can be a real thing, but it depends (on context). Here I could immediately understand what "find real windows" means since I know that you can hide windows and maybe make them without a "real" id/identifier (eg: real -> not acting/used in the usual user way, etc)
13:50
Ah, "it depends". One of my favorite tools for defending a hill I've chosen to die on :-p
My not-in-any-special-order one is also "Everything is possible" and it's reverse, all working accordingly with this one.
My IRL friends tell me I'm an expert in the art of moving goalposts
@Kevin but can you do it without the standard tools? How about both at once?
"could you move the goalposts with one hand tied behind your back, while whistling the Star Spangled Banner, during a hurricane? No? Some expert you are"
14:15
@Aran-Fey found something that works: github.com/howardjohn/pyty/blob/master/src/window_api.py you have to install namedlist, but you can probably make a pure python solution by knowing how this works (I think it uses a class to store the values passed to it on slots from what I seen). Just tried it on Win10, it list only the windows that is listed when you do Alt+Tab
Oh, a python port of the C++ code you posted earlier, nice
Ooh, promising
took a while to find since I was multitasking when talking here + tried a bunch of similar solution on SO (think 4)
I vaguely recall I bookmarked this github repo before, since I once wanted to make a port of some AutoHotKey Windows Manager I once found, but in Python. This is the closest I found to work with as a basis for that
Hmm, I think it's calling GetWindowInfo incorrectly
> Note that you must set the cbSize member to sizeof(WINDOWINFO) before calling this function.
but it worked when I tried it? Or is it a problem down the line
14:19
¯\_(ツ)_/¯
just try it like this: dpaste.org/88y5a/raw
this is what I did to make it work. You don't really need namedlist since as I said, it just store what you pass to it on __slots__ inside a class (there two print statement because I installed namedlist anyway). It run get_all_windows(), and that's it.
I get the impression that Microsoft adheres to the design principle of "be liberal in what you accept, and strict in what you emit". In other words, if you call an API method and put NULL into some fields that really shouldn't be NULL, the OS might say "... Meh, good enough" and give you a useful result anyway
I feel like this is similar to the "freedom" you have on Linux, but probably worse there (depending on your definition of worse)
I feel like it wouldn't be that bad if they at least documented it, but that's maybe too much to ask :|
Some of these allowances might not be formally documented. They might have been quietly introduced into the API in order to ensure backwards compatibility with a single very popular third party program. In that case, Microsoft would prefer that nobody actually know about the allowance, because they don't want anyone else using it.
"Ok, we'll let GetWindowInfo work without a proper cbSize, because Lotus Notes won't work otherwise. But don't tell nobody."
14:49
@Aran-Fey just tried this on the code above: if you use print on the cbSize value inside the class WINDOWINFO, I get 44, but if I do what's recommended (and as you mentioned too) and use ctypes.sizeof(WINDOWINFO) I get 64. Don't know if it's the right value, but at least it works on either cases.
@Kevin yeah, I can see some companies pushing for their own features getting supported and them not being detailed anywhere
I recall reading of many such examples on The Old New Thing, whose author is very very very proficient with the windows API, and has a great deal of first-hand experience in its development
maybe they might know if shadows are casted on separate windows :O (at least I'm curious if that's the case on Win10, since I know it's probably the case on older versions, based on what I posted above)
I haven't found any specific examples just clicking around, but I did find devblogs.microsoft.com/oldnewthing/20120913-00/?p=6613, which tells you something about the API's design philosophy: "The goal of Win32 was to provide as much backward compatibility with existing 16-bit source code as can be practically achieved."
also, found this too: stackoverflow.com/a/37503441/12349101 alternate solution, but it's less efficient, since it doesn't take into account metro apps, cloaked window, tools windows, and tray apps windows (unlike the other solution, which support ignoring all of these)
If Lotus Notes worked under the 16 bit source code, MS would have bent over backwards to keep it working under win32
14:55
since we're talking about Windows, did you know MSDOS is on github now?
I knew that since two years ago, but I think some people might not have noticed yet
Oh? I'm glad to hear it. Historically important software deserves to be preserved.
their calculator and calendar are open source too I think, but I might misrecall for those two. Here for MSDOS: github.com/microsoft/MS-DOS
Now find me SkiFree, Minesweeper, and Solitaire ;-)
(You do not have to actually find these for me)
I know about the latter two, but don't know what SkiFree is (without first googling I mean)
It's a game about skiing. Famous for its terrifying yeti creature, which inevitably devours the player character.
14:58
I see :o sounds weirdly unique for a Windows game
The yeti may or may not be a creative way to end the game before the process runs out of memory. Can't remember if that story is apocryphal.
Obligatory: xkcd.com/667
On a side note, I'm glad that Aran asked for the above though, since I wanted to do the same thing, but put it in a shelf/back burner for later.
now it's "done", at least for Win10...
@Kevin never saw this one, nice
My own "possible future projects" list has "create a little window manager thing" somewhere on it. It would be nice if I could create "preset" window layouts that I could restore at the push of a button. For example, Visual Studio on my left monitor, Edge on my middle monitor, and Notepad++ on my right monitor.
sounds like a tiling WM. Already is a thing on Linux. There also one or two Python/AutoHotKey Tiling WM (for Windows) if you want to dig around to do that
I wanted to do the same thing too, at least according to my list
the code I posted above from github is I think a good basis for that (look at the other files though since I only posted a link to a single one)
It would also be nice if I could move windows from one monitor to the other while the window is still minimized. It's awkward when I'm sharing my screen during a virtual meeting, and I need to open a firefox window, and I recall that firefox is currently minimized and displaying the Wikipedia page for SkiFree.
If I could move firefox to the monitor that I'm not sharing, and close the SkiFree tab, that would let me maintain my dignity.
I suppose in that specific case I could open an entirely new firefox instance. But some other applications are more stubborn about that kind of thing.
15:09
when you say monitor, do you mean virtual ones (eg: workspace, VNC, etc) or actual physical one (with a screen)
Actual physical ones.
As you say, if I dig around I can probably find something close to what I want. Digging around is also somewhere on my todo list.
Anonymous
15:24
If I have a "Process" class in python that does not start in "init" method like "Popen" does, but instead via a "start" method, how would I make so this class can be used as a context manager?
Anonymous
Like, I want to have these possibilities:

process = Process()
process.start()
process.terminate()

and

with Process().start():
    pass
Anonymous
Is this even possible?
Yes, you should be able to do it with contextlib.
import contextlib

class Process:
    @contextlib.contextmanager
    def start(self):
        print("Starting.")
        #allocate resources here
        try:
            yield None
        finally:
            print("Finishing.")
            #deallocate resources here

with Process().start():
    print("Doing things.")

#output:
#Starting.
#Doing things.
#Finishing.
Anonymous
Would it make sense yielding the "Process" object in the try block?
@Warcaith just curious, but why do you not use Popen? Unless it's for creating your own version of subprocess.Popen?
15:30
Yes, it would be fine to yield the process object. I believe it's a fairly common pattern to yield self in this way.
@Warcaith I would say yes, if whatever you'll run as a subprocess will have errors
Need help with Mailu mail server setup. How can I add sendinblue smtp relay in mailu?
Anonymous
@NordineLotfi We have built our own "Process" class that in practice wraps subprocess "Popen". Why you may ask? Well, we needed a way to automatic resolve the process to the right platform and avoid having to deal with platform specific arguments when you need to run the process. So whenever you create a "Process" in our framework, you'll either get a "WindowsProcess" or a "PosixProcess/LinuxProcess", much like pathlib does it.
Hmm, it occurs to me that my example code does not necessarily fit your first snippet, where you call terminate() manually. I must consider this.
Anonymous
@Kevin Hmm, why would it not work?
15:36
@Warcaith ah yeah, I recall you mentioned this once (and posted example snippet that mentioned this too)
If you decorate a function with contextmanager and then call it without using a with statement, nothing will happen. Try calling process.start() on its own, and "Starting." won't get printed.
Anonymous
@NordineLotfi Yeah. The main reason is that "Popen" constructor is a bunch of mixed platform and non-platform specific arguments, and we want to simplify some things for our users. :)
I think you can still do what you want if you skip contextlib, and implement __enter__ and __exit__ yourself. Not a huge amount of code required, but I do need to think through the loopy bits
Anonymous
@Kevin Oh, yeah. That's the problem, which (I guess) makes it kind of hard to make the start method acts like both a "standard function" and a "context manager".
Anonymous
:55626012 You mean implement __enter__ and __exit__ on the Process class?
Anonymous
15:40
The problem with that is that the "start" method have some arguments, and the "__enter__" method can't take any arguments. :(
Yeah, on the Process class. Or possibly in a helper class, depending on whether you want with Process() as foobar: to be legal
Anonymous
Yeah, it would work, but I need to move the arguments from the "start" method up to the constructor in that case, which is something that we'd probably not want to do.
Anonymous
But I could perhaps create a "open_process" context manager besides all of this, even if that's not as fun :P
I think you can keep your arguments in the start method. I will write a prototype.
Anonymous
Oh, really? I would love to see that!
Anonymous
Oh, so the only problem is when using the class without calling "start", right?
Anonymous
That would easily be fixed with just throwing an exception or something :)
Yes. It might be bad if start allocates a resource, and terminate tries to deallocate the resource. Then terminate might try to deallocate a resource that was never allocated to begin with.
In most cases I imagine you could implement a "look before you leap" kind of design, where you keep track of whether any resources are currently allocated and waiting to be deallocated. Then you can check that value inside terminate and smartly decide what to do
Anonymous
Hmm... yeah, the main problem here is that a resource is allocated in "start" and I can't check if it's allocated or not inside __enter__, as that happens before "start".
Something like:
class Process:
    def __init__(self):
        self.resource = None

    def start(self, x):
        print(f"Starting with argument {x}.")
        self.resource = allocate_thing()
        return self

    def terminate(self):
        if self.resource is None:
            print("Could not find resource to deallocate! (did you forget to call start()?)")
        else:
            print("Terminating.")
            self.resource.destroy()
            self.resource = None
@Warcaith I believe start happens before __enter__, actually
Anonymous
15:56
Oh, really? I'll try this out and see what'll happen! :)
Anonymous
Thank you, will be back with some results
16:08
Here's an alternative design that prevents the user from doing with Process():. dpaste.com/3WLR9KDU2.txt
I have a feeling that I'm making this more complicated than it needs to be. But if it works, it works.
Anonymous
Oh, that's perhaps better actually. Is there any downside of using the second approach?
Nothing comes to mind. It's slightly more lines of code?
Anonymous
Yeah, but that doesn't matter. :P
Anonymous
What I like with the first approach is that the user receives some information about what was missing:

print("Could not find resource to deallocate! (did you forget to call start()?)")
You could do something similar with the two class design. Put these methods in the Process class, and the user will know why with Process(): doesn't work.
    def __enter__(self):
        raise Exception("Process is not a context manager -- try Process().start(x) instead")
    def __exit__(self):
        pass #unreachable, theoretically
Plan B: don't provide a descriptive error message, the user deserves to suffer
raise Exception("Wouldn't you like to know ;-)")
"Send 1 bitcoin to the following wallet address to view your stack trace..."
Anonymous
16:23
Haha, that's a great suggestion.. I'm sure I'll get to keep my job after that!
Anonymous
Thank you, this works great!
@Warcaith Does start need to be part of the interface separately? Could you not just pass those arguments to the constructor (in addition to the existing ones), and then make it work just as a context manager?
(something something, prefer composition over inheritance)
@NordineLotfi they do close themselves. The only question is whether you tip the balance of opening new connections vs. The rate that the DB kills them off. You can be sitting on a problem for a long time and not know it
Anonymous
@KarlKnechtel It would, I guess, but first of all.. we want to be able to restart the process with different arguments that are in the "start" method, including that we're trying to have a API that behaves similar to our C++ API that is used by a couple of hundreds developers atm.
Anonymous
@KarlKnechtel What has this to do with composition over inheritance? :o
Anonymous
16:31
We're not subclassing "subprocess" or anything like that, just using it as a member of our own "Process" class.
@roganjosh yeah, I see what you mean. I think I saw somewhere that it can be set to 8 hours as the default amount of time before it closes the sleeping connections.
if before that, other connections happen, then it all compound and thus waste resources, etc
If "restart the process" is effectively identical to "close the existing process and start a new process", then I think passing the arguments to the constructor would be a fine idea
Rather than creating one Process instance that you call start() on twice, just create two Process instances
@NordineLotfi you can set it yourself. I think I gave a pretty comprehensive overview of the (potential) issue
yeah, you did give a lot of insight, Thank you
Anonymous
@Kevin Sure, that's correct. I'll rethink this and hear with the team about what they think, as we will move away from the C++ design in that case.
16:46
@Kevin Thanks - realized my platform was having the same "issue"...
"careful, call before (xyz)..." felt so wrong in an exception message.
I may have one or two of those in my own projects :-)
makes more sense to integrate into a context handler
and even then, you could add the notice to the user within the ctx.
although that feel wrong having anything with logging in a ctx.
17:09
@Warcaith oh, because of the name, I thought maybe you were using threads
agreed - I avoid shadowing commonly used class names. I prefer "xxxHandler" as a scheme.
but i'm a picky bitch...so
Anonymous
Don't hate me for this question, okay? But how do I override a name mangled method in my parent class?
Anonymous
I'm just curious about testing something.
Anonymous
:')
def _ParentName__methodname(self):
Anonymous
17:17
It didn't seem to work... but I think I know why now.. thanks! :p
you can always use __dict__ to get the reference name you need :)
Particularly useful in case someone defining protected methods, etc...
Anonymous
@KarlKnechtel I did actually change this now. I've always hated the "start" method, especially since you need to have "_process: Optional[Popen]" member attribute in the class that needs to be checked against different states everywhere. Now I'm guaranteed that the "_process" will be initialized everytime! :)
is it just me or does having Optional[Popen] anything just feel wrong?
Anonymous
@Aran-Fey Hmm, if I call __mangled_method in the base class, it doesn't seem that it uses the overrided __Base_mangled_method in the subclass.. :o
Anonymous
@Elysiumplain Well, what do you mean by wrong? It's just like any nullable attribute. But yeah, you can avoid it easily in Python.
17:30
what sort of dataclass would you end up with? feel mangled.
class Parent:
    def __init__(self):
        self.__mangled_method()

    def __mangled_method(self):
        print('Parent')

class Child(Parent):
    def _Parent__mangled_method(self):
        print('Child')

Child()  # Child
Works for me
don't think you called the method from child there.
oh you chained in your init... god damn, too smart.
This is why I don't usually bother with name mangling. If you want to access foo._bar outside of the Foo class, be my guest, but there be dragons
I like dragons, dragons are cool
true - technically it's as useful as typehints...lol
17:36
Dragons are cool, but you might get burned
like I said - call the dict dunder of the Parent from within Child and you should have the proper method name with scope you need.
at least then there isn't uncertainty on the override name.
@Kevin I'm wearing oven mitts
Oven mitts: check. Bulletproof shoes: check. Home address safely hidden from the next guy that has to maintain this code: check.
c'mon...we all know we're too vain to use the last guys code...
Yes, my hubris usually disallows it
Anonymous
17:44
@Aran-Fey Yeah, I think I made a typo with all the underscores..
17:56
@Warcaith I assumed so from: "uses the overrided __Base"
 
2 hours later…
20:22
As a PHP developer, trying to convert a codebase over to PHP, I'm struggling to understand what this piece of code does in terms of its looping logic.
Those are comprehensions. They are effectively for-loops that build a list item for item.
result = [expr for name in iterable if condition]
# is equivalent to
result = []
for name in iterable:
    if condition:
        result.append(expr)
    self._convert_showname_field_names_to_field_names()

    a = []
    for name in self._all_fields:
        if name.startswith(self._full_name):
            a.append(self._sanitize_name(name))

    b = []
    for name in self._all_fields:
        if '.' in name:
            b.append(name.rsplit('.', 1)[1])

    c = set(a + b)
    return list(c)
I believe this is what the code would look like, if it were not written with list comprehensions.
Awesome, that's so much easier for me to understand. Thanks guys!
👍
I see this github project effectively lets you use Wireshark from Python. I would have liked something like this the last time I had a project involving packet analysis.
Yeah. It utilizes an existing tshark (Wireshark) installation. tshark has some messy output on the CLI, so pyshark tries to clean up after Wireshark to get a more pleasant to work with packet collection.
 
3 hours later…
23:16
...I just looked up how to increment floats correctly (eg: 1.0 -> 1.1 instead of 2.0) and found this. This is a joke right? Why is it so hard to increment a float
I guess the only two way to make this better is either using AST and rewriting it so I can just use + or maybe a decorator.
seems like this could work, but need to add a check for floats or something hmm
23:43
nvm, I guess I'll do with just 0.1 instead.
nvm (again) this is still broken, so I still need to use Decimal (or what I said above).
Please do something with this (I'm out of close votes; see my comment) stackoverflow.com/questions/21710048/read-only-csv-files-python

« first day (4430 days earlier)      last day (739 days later) »