The mayor and council of the city shall have full power and authority by ordinance to regulate the speed and operation of railroad trains on, along or across the streets, avenues or alleys of the city, to make it a penal offense for any railroad company, its agents or employees to block or obstruct any street cr088ing, with railroad trains, cars or engines any longer than is necessary for said trains, cars or engines to pass over said crossings; and to regulate in any other way the running or operation of railway trains within the city limits, as it may deem necessary to protect and safeguard the public and to provide penalties for the violation of any of the provisions of this Section.