0
我是Python新手。我試圖使用一些多處理來使我的工作更快。首先我嘗試了一個例子,一切正常。這裏是代碼:Python中的多重處理在代碼到達時崩潰start()
from multiprocessing import Process
import time
def f(name, n, m):
if name == 'bob':
time.sleep(2)
print 'hello', name, ' ', n, m
def h():
g(1, 2, 3)
def g(a, s, d):
p = Process(target=f, args=('bob', a, s,))
t = Process(target=f, args=('helen', s, d,))
p.start()
t.start()
t.join()
p.join()
print("END")
if __name__ == '__main__':
print("Start")
h()
之後,我用相同的技術,我的代碼和錯誤出現。這是有問題的代碼的一部分:
if __name__ == "__main__":
night_crawler_steam()
def night_crawler_steam():
.
.
.
multi_processing(max_pages, url, dirname)
.
.
.
def multi_processing(max_pages, url, dirname):
page = 1
while page <= max_pages:
my_url = str(url) + str(page)
soup = my_soup(my_url)
fgt = Process(target=find_game_titles, args=(soup, page, dirname,))
fl = Process(target=find_links, args=(soup, page, dirname,))
fgt.start() #<-----------Here is the problem
fl.start()
fgt.join()
fl.join()
page += 1
def find_links(soup, page, dirname):
.
.
.
def find_game_titles(soup, page, dirname):
.
.
.
翻譯時達到fgt.start()一些錯誤出現:
Traceback (most recent call last):
File "C:/Users/��������/Desktop/MY PyWORK/NightCrawler/NightCrawler.py", line 120, in <module>
night_crawler_steam()
File "C:/Users/��������/Desktop/MY PyWORK/NightCrawler/NightCrawler.py", line 23, in night_crawler_steam
Traceback (most recent call last):
File "<string>", line 1, in <module>
multi_processing(max_pages, url, dirname)
File "C:/Users/��������/Desktop/MY PyWORK/NightCrawler/NightCrawler.py", line 47, in multi_processing
fgt.start()
File "C:\Python27\lib\multiprocessing\process.py", line 130, in start
self._popen = Popen(self)
File "C:\Python27\lib\multiprocessing\forking.py", line 277, in __init__
File "C:\Python27\lib\multiprocessing\forking.py", line 381, in main
dump(process_obj, to_child, HIGHEST_PROTOCOL)
File "C:\Python27\lib\multiprocessing\forking.py", line 199, in dump
self = load(from_parent)
File "C:\Python27\lib\pickle.py", line 1384, in load
ForkingPickler(file, protocol).dump(obj)
File "C:\Python27\lib\pickle.py", line 224, in dump
self.save(obj)
File "C:\Python27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "C:\Python27\lib\pickle.py", line 425, in save_reduce
return Unpickler(file).load()
File "C:\Python27\lib\pickle.py", line 864, in load
save(state)
File "C:\Python27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python27\lib\pickle.py", line 655, in save_dict
dispatch[key](self)
File "C:\Python27\lib\pickle.py", line 886, in load_eof
self._batch_setitems(obj.iteritems())
File "C:\Python27\lib\pickle.py", line 687, in _batch_setitems
raise EOFError
save(v)
EOFError
這正好和直到RuntimeError: maximum recursion depth exceeded
任何想法會有幫助!
如果您通過'None'而不是'soup',錯誤是否仍然相同?看起來這可能是酸洗的問題。 – janbrohl
這不是一樣的錯誤。使用無之後,我只是有使用湯的功能問題。我看到多處理過程是正確的。任何想法如何酸洗這個問題? –
你可以粘貼你在過程實例中使用的方法體嗎? find_links等我認爲有一個問題 –