procfs: Fix removing vanished processes in pidstats.reload_threads()

If a process disappears while iterating the loop in
pidstats.reload_threads(), we get a RuntimeError as shown below. This
is because we cannot remove an entry from a dictionary while iterating the
dictionary.

Reproducer:
1. Add the following line to the beginning of pidstats.reload_threads():
import pdb; pdb.set_trace()
2. Start some process
3. Start the python interpreter and proceed as follows:
[~/git/python-linux-procfs]$ python3
Python 3.6.8 (default, Jan  3 2019, 16:11:14)
[GCC 8.2.1 20181215 (Red Hat 8.2.1-6)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import procfs
>>> ps = procfs.pidstats()
>>> ps.reload_threads()
> /home/olysonek/git/python-linux-procfs/procfs/procfs.py(462)reload_threads()
-> for pid in self.processes.keys():
(Pdb) next
> /home/olysonek/git/python-linux-procfs/procfs/procfs.py(463)reload_threads()
-> try:

At this point, terminate the process started in step 2. Return to the
python interpreter:

(Pdb) continue
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/olysonek/git/python-linux-procfs/procfs/procfs.py", line 463, in reload_threads
    try:
RuntimeError: dictionary changed size during iteration

Signed-off-by: Ondřej Lysoněk <olysonek@redhat.com>
Signed-off-by: John Kacur <jkacur@redhat.com>
Signed-off-by: Jiri Kastner <jkastner@redhat.com>
diff --git a/procfs/procfs.py b/procfs/procfs.py
index c6f6589..b0ce251 100755
--- a/procfs/procfs.py
+++ b/procfs/procfs.py
@@ -459,12 +459,15 @@
 			self.processes[pid] = process(pid, self.basedir)
 
 	def reload_threads(self):
+		to_remove = []
 		for pid in self.processes.keys():
 			try:
 				self.processes[pid].load_threads()
 			except OSError:
 				# process vanished, remove it
-				del self.processes[pid]
+				to_remove.append(pid)
+		for pid in to_remove:
+			del self.processes[pid]
 
 	def find_by_name(self, name):
 		name = name[:15]