我編寫了一個使用Unit testing framework的GUI應用程序。 該應用程序在樹視圖中顯示所有找到的單元測試。 如果您單擊單元測試名稱,程序將運行此測試並顯示結果。 它的工作原理!單元測試框架:在新進程中運行測試
但是現在我希望每個測試用例都運行在一個新的進程中。 我創建了一個「工作線程」(帶有模塊線程),但是此線程也在同一進程中運行。
模塊「multiprocessing」是解決方案,但我遇到了問題,我的實施。 我把我的「測試執行代碼」在自己的功能和嘗試:
item = self.GetSelection()
name = self.GetItemText(item)
p = multiprocessing.Process(target=ExecuteTest, args=(name, item))
p.daemon = True
p.start()
但後來我得到了錯誤。
Traceback (most recent call last):
File "C:\a\b\c\hhh\a.py", line 577, in OnLeftDClick
p.start()
File "C:\Python26\lib\multiprocessing\process.py", line 104, in start
self._popen = Popen(self)
File "C:\Python26\lib\multiprocessing\forking.py", line 239, in __init__
dump(process_obj, to_child, HIGHEST_PROTOCOL)
File "C:\Python26\lib\multiprocessing\forking.py", line 162, in dump
ForkingPickler(file, protocol).dump(obj)
File "C:\Python26\lib\pickle.py", line 224, in dump
self.save(obj)
File "C:\Python26\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "C:\Python26\lib\pickle.py", line 419, in save_reduce
save(state)
File "C:\Python26\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python26\lib\pickle.py", line 649, in save_dict
self._batch_setitems(obj.iteritems())
File "C:\Python26\lib\pickle.py", line 681, in _batch_setitems
save(v)
File "C:\Python26\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python26\lib\pickle.py", line 548, in save_tuple
save(element)
File "C:\Python26\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "C:\Python26\lib\pickle.py", line 419, in save_reduce
save(state)
File "C:\Python26\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python26\lib\pickle.py", line 649, in save_dict
self._batch_setitems(obj.iteritems())
File "C:\Python26\lib\pickle.py", line 686, in _batch_setitems
save(v)
File "C:\Python26\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "C:\Python26\lib\pickle.py", line 396, in save_reduce
save(cls)
File "C:\Python26\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python26\lib\pickle.py", line 748, in save_global
(obj, module, name))
pickle.PicklingError: Can't pickle <type 'PySwigObject'>: it's not found as __builtin__.PySwigObject
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python26\lib\multiprocessing\forking.py", line 342, in main
self = load(from_parent)
File "C:\Python26\lib\pickle.py", line 1370, in load
return Unpickler(file).load()
File "C:\Python26\lib\pickle.py", line 858, in load
dispatch[key](self)
File "C:\Python26\lib\pickle.py", line 880, in load_eof
raise EOFError
EOFError
有沒有人有什麼想法?
「pickleable(這是一個詞?)」,那麼'pythonic'呢?或'voooooooooooom' – SingleNegationElimination