Please create an account to participate in the Slashdot moderation system

 



Forgot your password?
typodupeerror

Comment AI for debugging (Score 1) 248

Sometimes I use AI to write quick functions with bounds checking, it does a decent job, but it always needs tweaking.

AI shines for debugging, when I have something that "should" work, I copy/paste the errors or problem description into AI and ask "How to Fix ELI5"

Once, AI even suggested there was a bug in a library, and it was right.

Note: I pay for Google Gemini 2.5 Pro and find it the best for coding compared to Chat-GPT.

Gemini does a good job of breaking everything down.

Here is an example from a mysql session timeout (brokenpipe) a problem that I just fixed this morning, with the help of AI. :)

-- START Gemini Pro Session --

ELI5: Fixing "MySQL server has gone away (BrokenPipeError)"
The Problem Explained Like You're 5
Imagine you're on the phone with a friend (the MySQL server). You're talking, everything is fine. Then, you put the phone down for a while to do something else. Your friend, thinking you're done talking, hangs up. A little later, you pick up the phone and start talking again, but your friend is no longer there. All you hear is a dial tone. This is the "Broken pipe" or "MySQL server has gone away" error.

In your code, your application (you) was connected to the MySQL database (your friend). It kept the connection open in a "pool" of connections to be reused, which is efficient. However, the connection sat idle for too long, and the MySQL server, to save resources, automatically disconnected it (hung up). When your application tried to use that same connection again, it discovered the connection was dead, leading to the error.

This specific error trace shows that SQLAlchemy, a tool that helps your Python code talk to the database, tried to clean up (rollback a transaction) on a connection that had already been dropped by the server.

The Fix: How to Keep the Conversation Going
The most common and effective way to fix this is to tell SQLAlchemy to check if the connection is still alive before using it, or to regularly refresh the connection. Here are the recommended solutions, from most common to more specific:

1. Recycle Connections (pool_recycle) - The "Hang Up and Redial" Approach
This is the most common and generally recommended fix. You can tell SQLAlchemy to automatically close and replace connections that have been open for a certain amount of time. This time should be less than the MySQL server's wait_timeout (which is often 8 hours by default, but can be much shorter on some hosting providers). A safe value is often 3600 seconds (1 hour) or less.

When you create your SQLAlchemy engine, add the pool_recycle argument:

Python

from sqlalchemy import create_engine

# Add pool_recycle to your engine creation
engine = create_engine(
        "mysql+pymysql://user:password@host/dbname",
        pool_recycle=3600
)
2. Pre-Ping Connections (pool_pre_ping) - The "Are You Still There?" Check
This option tells SQLAlchemy to send a very small, quick message (a "ping") to the database to see if the connection is still active before your application uses it. If the ping fails, SQLAlchemy will replace the dead connection with a new one. This is very reliable but adds a tiny bit of overhead to each database operation.

Python

from sqlalchemy import create_engine

# Add pool_pre_ping to your engine creation
engine = create_engine(
        "mysql+pymysql://user:password@host/dbname",
        pool_pre_ping=True
)
For many applications, pool_pre_ping=True is the most robust solution.

3. Adjusting Server-Side Timeouts (If you control the server)
If you have administrative access to your MySQL server, you can increase its wait_timeout value. This tells the server to wait longer before hanging up on idle connections. You would typically change this in your MySQL configuration file (my.cnf or my.ini).

[mysqld]
wait_timeout = 28800
After changing this, you must restart the MySQL server. However, it's often better to make your application more resilient (using pool_recycle or pool_pre_ping) than to rely on server-side settings.

4. For Large Queries: Check max_allowed_packet
Less commonly, this error can occur if you are trying to send a very large piece of data to the database that exceeds the server's max_allowed_packet size. If you are inserting or updating a row with a lot of text or a large binary file, and the error happens consistently with that operation, you may need to increase this value in your MySQL server's configuration file.

[mysqld]
max_allowed_packet=64M
Again, this requires server access and a restart of the MySQL service.

Summary
In most cases, the simplest and most effective way to fix the "MySQL server has gone away" error is to configure SQLAlchemy's connection pool to handle stale connections gracefully. Start by adding pool_pre_ping=True or a reasonable pool_recycle value to your create_engine call. This ensures your application doesn't try to talk on a dead line.

Comment Re:Sorry I just woke up⦠(Score 3, Interesting) 10

Doesn't ANYBODY but me remember that "Napster" was actually RealNetworks? You know, the old Real.com that was the Internet's first scale, commercial streamer? Real became Rhapsody for several years. Rhapsody had no name recognition, so they bought the Napster name from it's owners... BEST BUY.

It gets weirder. Rhapsody had been Sonos' partner streaming service - and Rhapsody is also... I HEART RADIO. Now the whole Napster lot got dumped in the lap of venture capital vultures.

Comment Re:Good (Score 3, Insightful) 104

>It's one of the few segments in IT where you're not directly at constant risk of being replaced by an H1B.

Truth. One of the reasons why I keep gravitating back to defense work. Only since around 2004 or so; there's now this "government shutdown" nonsense, which is a bit of a vicious circle, because programs get fucked over, then you have to roll off the contract and find work on another. And sometimes, there isn't any. (happened to me at Lockheed), so some people have to cycle back into the private sector for a few years (which isn't a bad thing; because THAT is where you pick up new skills, to be honest). Then when some asshole "businessman" crashes the business and does layoffs (to replace you with H1B's), you're back on the street again, and you end up back in the "safe" sector: defense. Oh, and if your Clearance expires while you're in the private sector, then the contractor just pays the $10k (or whatever it is now) to re-do your investigation. This has happened to me twice now.

Comment Re:Awful.. (Score 1) 163

I am with you brother, it is good for simple things but the indenting for codeblocks and gymnastics for magic methods and mixed programming paradigms.
I use C most of the time and BYTHON is something I want to check out.

def print_message(num_of_times) {
        for i in range(num_of_times) {
                print("Bython is awesome!");
        }
}

if __name__ == "__main__" {
        print_message(10);
}./qu

Comment Re:The gain on this amplifier was negligable (Score 3, Insightful) 50

Coding is not the point of the CS50 class.
The point is code literacy and the intellectual pursuit of computer science.

CS50 isn't just about learning to write code; it's about fostering computational thinking and code literacy. While coding is a crucial tool, the core of CS50 lies in understanding the underlying principles of computer science. The course meticulously builds a foundation, starting with fundamental building blocks like variables, data types (booleans, integers, etc.), control flow (if/else statements, loops), and functions. It then progresses to more complex concepts like data structures (arrays, linked lists, trees), algorithms (searching, sorting), and algorithm analysis using Big O notation. This journey from the micro to the macro gives students a holistic view of how software works.

CS50 empowers you to dissect and comprehend code, regardless of the specific language. Instead of just blindly writing lines of code, you learn to think algorithmically, breaking down problems into logical steps that a computer can execute. This understanding is crucial for leveraging tools like AI code generation. Imagine using an AI assistant like Claude: with a CS50 background, you wouldn't just accept the generated code at face value. You'd be able to critically evaluate it, understand its logic, identify potential flaws, and modify it to perfectly fit your needs. You become a collaborator with the AI, not just a passive user.

Harvard's commitment to making CS50 accessible to the world is commendable. The course's comprehensive curriculum, combined with its engaging teaching style and extensive online resources, has democratized computer science education. The availability of variations like CS50 AI further demonstrates the program's dedication to exploring cutting-edge topics and preparing students for the future of technology. CS50 isn't just a course; it's an investment in developing the next generation of problem solvers and innovators.

CS50 is a brilliant class and I applaud Harvard putting it out there for the world. Thank you HARVARD! I wish I could have gone to Harvard.

Comment Re:Windows/NT ! From the makers of edlin! (Score 4, Interesting) 167

Some quibbles: IBM prevented 32-bit OS/2 for 80386 not from bad planning, but an internal struggle to keep 32-bit PCs from biting into the AS400 mini computer business, and there were internal wars for the board approvals.

This was the end of the line for Gates's frustration with IBM, as OS/2 took resources from projects he and Balmer were convinced would take off. Publicly claiming that upcoming Windows 3.0 would not be "Presentation Manager Lite", MS still death-marched developers to produce the release, while devs allotted to IBM sat on their hands or did code reviews for IBM managers. Win 3.0 Program Manager kicked ass on Presentation Manager, it was definitely not "lite" - and it ditched all the heavy-baggage of IBM SNA requirements.

"OS/2 NT" is a bit misleading. Late in the endgame of the IBM/MS relationship, Gates discovered that Dave Cutler was being cut away from DEC, with a recalibration of Prism and the future of Alpha. Cutler had begun a 64-bit microkernel evolution of his VMS system. OS/2 3.0 was on the boards, still dragging MS resources and tying up IP. Gates hired Cutler to build an alternative, skunk works kernel from his Prism design work, with the hope of porting the Windows System 32 layer with dependencies etc. When the last bitter contract work was delivered for IBM, Cutler and the Windows team ground out the hard work of delivering their kernel, TCP stack, and Windows 3.11 port —Windows NT.

Most of this stuff is well-covered in Carroll's "Big Blues" along with Zachary's "Show Stopper!: The Breakneck Race to Create Windows NT". I had a small part at the NT launch in Moscone Center, working for a ghost-writer on the Sybex NT book that launched at that event

Comment Re:Slashdot Ad Blocking Extra Broken (Score 2) 40

I'm probably the lowest UID still occasionally active on Slashdot. It's a habit, that I'd be sorry to see go. This site is still my first pinned tab in Firefox.

Hell, I still even check things out on https://ancillary-proxy.atarimworker.io?url=https%3A%2F%2Feverything.blockstacke..., even though they are throwing me an expired cert right now!

Remember Blockstackers?

Slashdot Top Deals

Nothing ever becomes real till it is experienced -- even a proverb is no proverb to you till your life has illustrated it. -- John Keats

Working...