Follow Slashdot blog updates by subscribing to our blog RSS feed

 



Forgot your password?
typodupeerror

Comment AI for debugging (Score 1) 247

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:But, but, but..... (Score 1) 153

I was waiting for this one to come up, but yes, some things are absolutely worth eradicating. Nobody is petitioning to bring back polio or smallpox. Mosquito larvae compete for resources with other insect larvae, so fewer mosquitoes will mean more of whatever they're competing with for resources, which could replace them in the food chain.

Comment Re:Cajun First! (Score 2) 166

You know that French was literally **banned** in Louisiana by a constitutional amendment until 1974, right? Children caught speaking French even faced corporal punishment in schools. So rag about "whiney Frenchies" all you want, but attempts to stamp out French language and culture in North America were very much real until very recently. The French explored most of North America and set up settlements across the continent by the early 1700s, and many places still carry anglicized French names. However, the English scored a decisive victory taking out the French army in North America in 1759, over 100 years before the US Civil War FWIW. The Cajuns didn't start out in Louisiana; they were forcibly deported there by the British. A funny thing happens when you oppress a population for a few hundred years; they tend to remember that oppression:

https://en.wikipedia.org/wiki/...

So while we bend over backwards to accommodate Spanish speakers today, that courtesy was absolutely not extended to the French that had been here from 1599 onwards, 8 years before the English in Jamestown.

https://en.wikipedia.org/wiki/...

Granted, the French lost the war, and to the victors go the spoils, but the English and French had a long history of war back in Europe, and that meant the French in North America were treated as 2nd class citizens.

Now, I disagree with forcing prioritization of French programming, and I also disagree with language laws in Quebec that restrict the use of English, but I think it's fine to ask that French content at a minimum be featured on the platforms. It doesn't change the complicated history of French in North America, but if we're going to be supportive of Spanish speakers in North America, why wouldn’t we also be supportive of French speakers who were here before the English?

Comment Re:This will reverse the gains from covid (Score 1) 63

I don't know if you're Archie Bunker or an Archie Bunker parody, but in Mississippi's public schools, the student population is predominantly non-White, specifically Black (48.5%), Hispanic / Latino (5.2%), and two or more races (3.3%), comprising 57% of the student body. White students, while the 2nd largest group, are a minority (43.0%).

Now, which of these groups is the target of your smack down of Mississippi?

Comment Re:A lot of PR BS and spin (Score 1) 35

Zig does exactly this in a C-like way without the C++-like syntax of Rust, while enabling lower memory consumption and lower-level performance optimizations than Rust. Zig is still young, but I expect it to eventually replace Rust use cases in Linux, specifically because it's a better C rather than a better C++.

Comment Re:What is it for? (Score 1) 120

Beyond dev work, spatial home video and photos are mind-blowing. The spatial photos alone make it worthwhile to me. The spatial upscaling of scanned photos works incredibly well. I've used an Oculus before, comparing it to the VP is like comparing a Corolla to a Bentley; they're not at all in the same class when it comes to visual fidelity. That said, it's expensive, it does feel noticeable in weight after a while, and the battery pack should have more capacity. Another missed opportunity is that you have to wear it to do system updates and settings, but it really should have an app like the Watch does. The selection of immersive content on ATV is very limited as well. The killer use case would be live sporting events; it's a shame that hasn't happened considering the resources Apple has at its disposal. However, gripes aside, it's an amazing device.

Comment 500 million euros ... (Score 2, Interesting) 214

That's less than the federal grants a single university (UNC) got in 2022. [begin sarcasm] I'm assuming the salaries offered to relocating researchers are going to be in the €200K range at a 32% income tax rate with a regulatory environment that is going to allow them to do research unimpeded by overbearing regulations and abundant 2800 sqft family homes near major research centers in the €700K range? [end sarcasm]

There is more to attracting talent than a token contribution to a communal pool. Europe has lower wages, higher income taxes, higher property prices, and onerous regulations. There was a time when the ancillary benefits of Europe exceeded those downsides, but those times are in the past. Regardless of what misguided nonsense our tariff-in-chief pushes through in his imaginary state-of-emergency, I have no concern about a wholesale brain drain from the US.

I legitimately feel for researchers whose funding got cut. It’s undoubtedly a very unpleasant situation for them. I'm sure they have families to feed and this is going to be hard on them. However, the majority of the grants that were cut were not for STEM or medical research, contrary to the narrative pushed by detractors. Researchers whose funding got cut have options, they can seek out private backers to fund their research assuming there's value to be created from it. If Europe wants to bring in swaths of displaced social science researchers, that's absolutely their prerogative, but the cold hard truth is that the net impact on the US economy from this will be imperceptible.

Comment Re:Not what the narrative says (Score 1, Informative) 171

It's a virtual paradise, barely 5000 crimes a month and only 10% involve physical violence!!!

https://www.civichub.us/ca/san...

Last time I was in the city, a guy took a dump in front of the window of the coffee shop I was in, but that was performance art, I just misunderstood it at the time.

Slashdot Top Deals

Someday your prints will come. -- Kodak

Working...