Ram Rachum wrote:
1. I'm making a program that lets people lease machines. They can issue a command to lease 7 machines. ... If everything goes fine, I do pop_all on the exit stack so it doesn't get exited and the machines stay leased,
Seems to me that would be done more easily and clearly without involving a context manager at all: machines = [] try: for i in range(num_machines_required): machines.append(lease_machine()) except AllMachinesInUseError: for machine in machines: release_machine(machine) del machines[:] A context manager is a tool to be used if it helps. If it doesn't help, don't be afraid to not use it!
2. I have a test suite that creates a temporary folder to put files that are used by the test. ... But, if the test fails I want to move the temporary folder away into a dedicated folder
Again, don't use a context manager, just write a try-except that does what you want. -- Greg _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/