Tuesday Debug Diary | First Open-Source PR Spent hours chasing a “hang.” Turned out to be an asyncio + keep_alive design clash. Bug: Browser(keep_alive=True) + asyncio.run() → program never exits. Why it broke keep_alive=True keeps background asyncio tasks alive (watchdogs, CDP handlers, websockets). asyncio.run() expects a clean event loop. Mismatch = loop never closes. Not a deadlock. A lifecycle issue. Context Python/asyncio isn’t my strongest language I picked this up purely to understand how the system works under the hood. Lesson If background tasks are intentional → use one long-lived event loop. Multiple asyncio.run() calls = trouble.First OSS PR. Not merged. Real learning happened. #OpenSource #Python #Debugging #LearningInPublic #FirstPR
Debugging asyncio + keep_alive in Python
More Relevant Posts
-
Day 331: Is my code actually slow? (Time) ⏱️ Benchmarking 101 "Is this list comprehension actually faster than a for-loop?" Instead of guessing, I measure it. The time module is the simplest way to benchmark your code performance. In algorithmic contests (like CodeVita), milliseconds matter. import time start = time.time() # The code you are worried about total = 0 for i in range(1000000): total += i end = time.time() print(f"Time taken: {end - start:.5f} seconds") 💡 Pro Tip: For more advanced benchmarking, check out the timeit module, but for quick checks, time is my daily driver. #Performance #Python #Optimization #Algorithms
To view or add a comment, sign in
-
𝗘𝘃𝗲𝗿 𝗻𝗼𝘁𝗶𝗰𝗲𝗱 𝘀𝗼𝗺𝗲 𝘀𝗼𝗹𝘂𝘁𝗶𝗼𝗻𝘀 𝗼𝗻 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 𝘁𝗵𝗮𝘁 “𝗯𝗲𝗮𝘁 𝟭𝟬𝟬%”? __import__("atexit").register( lambda: open("display_runtime.txt", "w").write("0") ) Looks like a hacker trick. Feels smart. 𝗪𝗵𝗮𝘁 𝘁𝗵𝗶𝘀 𝗰𝗼𝗱𝗲 𝗮𝗰𝘁𝘂𝗮𝗹𝗹𝘆 𝗱𝗼𝗲𝘀 (𝗹𝗶𝗻𝗲 𝗯𝘆 𝗹𝗶𝗻𝗲): • 𝗮𝘁𝗲𝘅𝗶𝘁 → runs code when the program is about to exit • 𝗿𝗲𝗴𝗶𝘀𝘁𝗲𝗿(...) → hooks a function to run at the very end • 𝗼𝗽𝗲𝗻(...).𝘄𝗿𝗶𝘁𝗲("𝟬") → overwrites the file LeetCode reads to show runtime So when execution finishes, the runtime file gets replaced with 0. The algorithm didn’t get faster. Only the displayed number did. 𝗟𝗲𝘀𝘀𝗼𝗻: If you don’t understand how a metric is calculated, you’ll optimize the metric — not the system. #moxcode #Python #LeetCode #Engineering #SystemsThinking #LearningInPublic
To view or add a comment, sign in
-
-
Day 40 / 100 – Longest Consecutive Sequence (O(n) Solution) => Finding the length of the longest sequence of consecutive integers in an unsorted array. Time Complexity: O(n) Space Complexity: O(n) => Approach used: Store all numbers in a set for constant-time lookup Only start counting when the current number is the beginning of a sequence (num - 1 not present) Expand forward to count consecutive elements Track the maximum streak length Learning Insight This problem highlights how hashing can eliminate unnecessary sorting and drastically improve performance. By identifying sequence start points, we avoid redundant work and achieve true linear-time complexity. A great example of combining problem insight + the right data structure to write optimal solutions. Code pushed to Git 🚀 👉 https://lnkd.in/gF-2n4tn #100DaysOfCode #Python #DSA #Hashing #LeetCode #CodingJourney #ProblemSolving #Algorithms
To view or add a comment, sign in
-
THE PAIN We've all been there. Debugging a complex loop that spirals out of control, losing track of state, and wondering why the output is so wrong. It’s frustrating and eats up valuable time. THE INSIGHT Often, this complexity arises from trying to force iterative solutions onto problems that have a naturally self-referential structure. We get tangled in managing indices and temporary variables. THE FIX Embrace recursion. Think about breaking a problem down into smaller, identical versions of itself. For instance, calculating factorial: factorial(n) is n factorial(n-1) * The base case: factorial(0) is 1 This maps directly to a simple Python function: def factorial(n): if n == 0: return 1 else: return n * factorial(n-1) THE OUTCOME Clearer code. Fewer bugs. Better focus on the problem itself, not the mechanics of iteration. #Python #Recursion #SoftwareEngineering #SeniorEngineer #CodingTips
To view or add a comment, sign in
-
-
Day 2/100 – #100DaysOfLeetCode 🚀 🧩 Problem: LeetCode 242 – Valid Anagram (Easy) At first glance, the problem looks simple: 👉 How do we check if two strings are just rearrangements of each other? The idea is straightforward. If two strings are anagrams, they must: 1️. Have the same length 2️. Contain the same characters with the same frequency So I started by checking the length. Then I sorted both strings and compared them. If the sorted versions match, the strings are anagrams. class Solution: def isAnagram(self, s: str, t: str) -> bool: if len(s)!=len(t): return False return sorted(s)==sorted(t) ⏱ Time | Space: O(n log n) | O(n) 📌 Key Takeaway: Problems like this highlight a recurring pattern in DSA. Sorting and frequency counting are powerful tools for string manipulation. #leetcode #dsa #python #strings #coding #codingchallenge #problemSolving #learning
To view or add a comment, sign in
-
-
🗄️ dataclass + Protocol Dict-based code scales until the first refactor. Passing dicts feels fast. Flexible. Obvious. Then the system grows. Key mismatches appear at runtime. Contracts live in Slack threads. Refactors feel risky. The fix is explicit contracts. Use dataclass for shape. frozen=True makes it immutable. Safer for shared state. Use Protocol for boundaries. Any class with a matching get() method satisfies the contract. No inheritance required. Refactors become predictable. Testing becomes simpler. Type checkers catch mismatches early.🔵 ⚪ #Python #SoftwareArchitecture #BackendDevelopment
To view or add a comment, sign in
-
-
Day 39 / 100 – Implement Queue using Stacks => Designing a queue (FIFO) behavior using two stacks (LIFO). Time Complexity: Push: O(n) Pop: O(1) Peek: O(1) => Strategy used: Use one primary stack to maintain queue order Use a helper stack during push to reverse elements Always keep the front of the queue on top of the primary stack #LearningInsight This problem reinforces how data structures can be transformed into one another using controlled operations. By carefully managing stack order, we can achieve queue behavior while keeping pop and peek efficient. Strong fundamentals make complex systems easier to reason about. Code pushed to Git https://lnkd.in/gNunRSqn #100DaysOfCode #Python #DSA #Queue #Stack #LeetCode #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
Daily LeetCode Progress | Day 3 ✅ LeetCode 2183: Count Array Pairs Divisible by K ✔️ Brute force doesn’t scale for this problem, so I applied a math + hashing optimization to efficiently count valid pairs. 🧠 Approach: Instead of checking every pair, each number is reduced using gcd(num, k). Two values form a valid pair if their reduced forms together satisfy the divisibility condition. How it works: • Maintain a frequency map of k / gcd(num, k) • For each number, count compatible values seen so far • Update the map and accumulate results in a single pass This avoids nested loops and remains efficient even for large inputs. ⏱ Time Complexity: O(n × d) 📦 Space Complexity: O(d) (where d is the number of divisors of k, typically small) 🔑 Takeaway: Transforming a brute-force pairing problem into a number-theory-driven frequency problem can drastically improve performance. DSA grind continues 💪 #LeetCode #DSA #ProblemSolving #Python #CodingJourney
To view or add a comment, sign in
-
-
🚀 𝟲𝟬 𝗗𝗮𝘆𝘀 𝗼𝗳 𝗖𝗼𝗱𝗶𝗻𝗴 | 𝗗𝗦𝗔 𝘅 𝗥𝗲𝗮𝗹 𝗪𝗼𝗿𝗹𝗱 𝗣𝗿𝗼𝗷𝗲𝗰𝘁𝘀 #Day33 | 𝗪𝗲𝗯𝘀𝗶𝘁𝗲 𝗖𝗿𝗮𝘄𝗹𝗲𝗿 Built a Website Crawler using Depth-First Search (DFS) to traverse linked web pages starting from a root page. Focused on: • DFS-based graph traversal • Visited tracking to avoid cycles • Adjacency list representation • Understanding how basic crawlers explore websites 📌 𝗖𝗼𝗱𝗲 𝗮𝗻𝗱 𝗱𝗼𝗰𝘂𝗺𝗲𝗻𝘁𝗮𝘁𝗶𝗼𝗻: https://lnkd.in/gxzGJ4nB Feedback and suggestions are welcome. #DSA #Graphs #DFS #WebCrawler #Python #60DaysOfCoding #LearningInPublic #SoftwareEngineering
To view or add a comment, sign in
-
Surprise. I have a blog - https://lnkd.in/gxmYvqZ2 - and I made a post yesterday regarding something I've been playing with. Does #Elixir need an image generation library that wraps the latest versions of #stablediffusion and #flux? I'm not sure but that's the question I'm asking with this post. The teams behind #Nx and #Pythonx recently brought in the feature of being able to share memory from Python / Numpy to Nx. Here's a practical application of it. I'm happy to get feedback on this so I can gauge whether this is something people actually want or they'd rather just use the technique of using Nx as the bridge and use Elixir as the orchestrator for the Python libraries. You can DM me if you don't want to comment publicly. In particular I'd like to know 'Who is this for?' as detailed in the final section of the post. Read the post here and comment below: https://lnkd.in/gMXe-JzP
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development