Added multiprocessing support to generate testcases in finalize (#697)

* Added multiprocessing support to generate testcase in finalize

* Improve the code using @feliam suggestions

* Fixed multiprocessing code. Now it really seems to work!™
This commit is contained in:
ggrieco-tob 2018-02-02 15:37:24 -03:00 committed by Mark Mossberg
parent 97307906c5
commit 2f2b081aa9

View File

@ -7,6 +7,8 @@ from .platforms import evm
from .core.state import State from .core.state import State
import tempfile import tempfile
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from multiprocessing import Process, Queue
from Queue import Empty as EmptyQueue
import sha3 import sha3
import json import json
import logging import logging
@ -1238,9 +1240,25 @@ class ManticoreEVM(Manticore):
def finalize(self): def finalize(self):
#move runnign states to final states list #move runnign states to final states list
# and generate a testcase for each # and generate a testcase for each
lst = tuple(self.running_state_ids) q = Queue()
for state_id in lst: map(q.put, self.running_state_ids)
def f(q):
try:
while True:
state_id = q.get_nowait()
self.terminate_state_id(state_id) self.terminate_state_id(state_id)
except EmptyQueue:
pass
ps = []
for _ in range(self._config_procs):
p = Process(target=f, args=(q,))
p.start()
ps.append(p)
for p in ps:
p.join()
#delete actual streams from storage #delete actual streams from storage
for state_id in self.all_state_ids: for state_id in self.all_state_ids: