This is a really fun one! I would approach it by figuring out how many people you can pack into the starting area, because that is when you'll have them most densely packed and I think it will be the limiting factor. Later on it the race, people need more space (running takes more space than standing), but people are spread out - most finish times are between 3 and 6 hours, and people therefore spread out quite a bit.
I would assume that each person needs about 1 m^2 to properly get started (you can pack people more when they are just standing, but they need to be able to stretch and start running, so you'll need more space in this scenario), and that the starting areas is about 25 m wide (5 lanes at 4 meters width + side walk). Let's assume that the starting area stretches along the road for a good 200 m. This would give you 25 m * 200 m/ 1 m^2 = 50000 people.
The actual number is closer to 40000 for each of those marathons, but I think the approach is valid and you would just need to tune the numbers to reflect the street layout. It's also possible that other restricting factor play in - both Boston and London are old cities, so there could be narrower streets on the route, or it could be that supply stands are a limiting factor.