Reddit Programming
210 subscribers
1.22K photos
124K links
I will send you newest post from subreddit /r/programming
Download Telegram
FlexGuard: using eBPF to detect critical section preemptions and switch between spinlocks (fast) and blocking locks (resistant to oversubscription)
https://www.reddit.com/r/programming/comments/1o83b2m/flexguard_using_ebpf_to_detect_critical_section/

submitted by /u/loulan (https://www.reddit.com/user/loulan)
[link] (https://dl.acm.org/doi/10.1145/3731569.3764852) [comments] (https://www.reddit.com/r/programming/comments/1o83b2m/flexguard_using_ebpf_to_detect_critical_section/)
Open Source as Career Catalyst
https://www.reddit.com/r/programming/comments/1o8n320/open_source_as_career_catalyst/

<!-- SC_OFF -->Contributing to #opensource can shape your skills, strengthen your professional identity, and open doors you didn’t even know existed. Do you have examples of how open source has helped your career? <!-- SC_ON --> submitted by /u/WalrusOk4591 (https://www.reddit.com/user/WalrusOk4591)
[link] (https://www.punch-tape.com/blog) [comments] (https://www.reddit.com/r/programming/comments/1o8n320/open_source_as_career_catalyst/)
Dialogs that work everywhere – dealing with the timeout
https://www.reddit.com/r/programming/comments/1o8z31v/dialogs_that_work_everywhere_dealing_with_the/

<!-- SC_OFF -->Miniterface (https://github.com/CZ-NIC/mininterface) is a toolkit that makes dialogs that work everywhere, as a desktop, terminal, or a browser app. Recently, I've added a timeout feature that auto-confirms the dialog in few seconds. As the library guarantees the dialogs work the same way everywhere, this was technically challenging, take a look at the techniques used for each interface. GUI (tkinter) I feared this will be the most challenging, but in the contrary! Simply calling the countdown method, while decreasing the time to zero worked. In the method, we use the tkinter after to set another timeout self.after_id = self.adaptor.after(1000, self.countdown, count - 1) and changed the button text self.button.config(text=f"{self.orig} ({count})"). When countdown is at the end, we click the button via self.button.invoke(). The moment user defocuses the button, we stop the counting down. self.button.bind("", lambda e: self.cancel() if e.widget.focus_get() else None) Do you see the focus_get? This is to make sure another widget in the app has received the focus, we don't want to stop the counting down on changing the window focus via Alt+tab. https://github.com/CZ-NIC/mininterface/blob/main/mininterface/_tk_interface/timeout.py TUI (textual) The TUI interface is realized via the textual (https://textual.textualize.io/) framework. On init, we create an async task asyncio.create_task(self.countdown(timeout)), in which there is a mere while loop. The self.countdown method here is called only once. while count > 0: await asyncio.sleep(1) count -= 1 self.button.label = f"{self.orig} ({count})" As soon as while ends, we invoke the button (here, the invocation is called 'press') via self.button.press(). https://github.com/CZ-NIC/mininterface/blob/main/mininterface/_textual_interface/timeout.py text interface The fallback text interface uses a mere built-in input(). Implementing counting down here was surprisingly the most challenging task. As we need to stop down counting on a keypress (as other UIs do), we cannot use the normal input but meddle with the select or msvcrt packages (depending on the Linux/Win platform). The counting is realized via threading, we print out a dot for every second. It is printed only if input_started is false, no key was hit. if not input_started.is_set(): print(".", end='', flush=True) The code is the lengthiest: https://github.com/CZ-NIC/mininterface/blob/main/mininterface/_text_interface/timeout.py Conclusion Now, the programmer can use the timeout feature on every platform, terminal, browser, without actually dealing with the internal implementation – threading, asyncio, or mainloop. This code runs everywhere: from mininterface import run m = run() print(m.confirm("Is that alright?"), timeout=10) # True/False <!-- SC_ON --> submitted by /u/the-e2rd (https://www.reddit.com/user/the-e2rd)
[link] (https://cz-nic.github.io/mininterface/Mininterface/#mininterface.Mininterface.confirm) [comments] (https://www.reddit.com/r/programming/comments/1o8z31v/dialogs_that_work_everywhere_dealing_with_the/)