"At" is a very specific time, so if you say you will finish homework at 4:00, it means exactly at this time. We use "by" to show anytime between now and a point in the future. So if you finish homework by 4:00, it means anytime between now and 4:00.
Likewise, if you take up swimming by the summer, it means anytime between now and summer. If you do it in summer, that means only in summer (i.e., not winter or spring).