device.py: fix _subprocess_Popen cleanup.

Every time gdbclient.py finishes it's giving this error:

Exception TypeError: 'must be type, not None' in <bound method
_subprocess_Popen.__del__ of <adb.device._subprocess_Popen object at
0x7fdd48e76850>> ignored

Basically super(_subprocess_Popen, self) was failing because at that
point _subprocess_Popen is None since global teardown had already
deleted the reference.

This fix saves local references to required global objects so that they
stick around until we're done with them. We may want to start looking
into making _subprocess_Popen a context manager instead, usage won't be
as convenient but __del__() does not scale to general use well. For now
though this CL seems to solve the problem for gdbclient.py.

Change-Id: I6c2a9fe0c108ae600cf05eb3b887d56959c7308e
1 file changed