Re: Keeping context-manager object alive through function calls

2015-11-10 Thread Ben Finney
Pablo Lucena writes: > In order to keep the SSH session open and not have to re-establish it > across function calls, I would like to do add an argument to > "do_stuff" which can optionally return the SSH session along with the > data returned from the SSH session, as

Keeping context-manager object alive through function calls

2015-11-10 Thread Pablo Lucena
I am running into a bit of an issue with keeping a context manager open through function calls. Here is what I mean: There is a context-manager defined in a module which I use to open SSH connections to network devices. The "setup" code handles opening the SSH sessions and handling any issues,

Re: Keeping context-manager object alive through function calls

2015-11-10 Thread Steven D'Aprano
On Wednesday 11 November 2015 09:36, Pablo Lucena wrote: > I am running into a bit of an issue with keeping a context manager open > through function calls. Here is what I mean: [...] > In order to keep the SSH session open and not have to re-establish it > across function calls, I would like to

Re: Keeping context-manager object alive through function calls

2015-11-10 Thread Chris Angelico
On Wed, Nov 11, 2015 at 9:36 AM, Pablo Lucena wrote: > And calling it as such: > > def do_more_stuff(device): > gen = do_stuff(device, return_handle=True) > data, conn = next(gen) > output = conn.send_command("show users") > #process output... > return