I am trying to use wicd-curses to connect my raspberry pi to a wifi network, and for that I am accessing the pi through ssh having it connected to the wifi network created by my iphone. The thing is that as soon as I try to connect to the other wifi network, the connection with my iPhone's network is lost and I think that this terminates the process of connecting to the new network and it gets stuck. Is there any way to avoid this?
Mosh is what I've used. It is designed for exactly this use case. I use it on a laptop that switches networks all the time: public, VPN, wired, 4g. So long as your packets can get there, mosh will reconnect seamlessly.
Additionally, on the host itself, screen is incredibly useful for use cases where you need to start a long running process but might need to disconnect and want to check back on it later. I use this to stay logged into IRC on my pi, for example, so I can log IRC and rejoin the discussion at any point.