Windows下 jupyter notebook 运行multiprocessing 报错的问题与解决方法
生活随笔
收集整理的這篇文章主要介紹了
Windows下 jupyter notebook 运行multiprocessing 报错的问题与解决方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 測試用的代碼
- 錯誤
- 解決方法
測試用的代碼
下面每一個對應一個jupyter notebook的單元格
import time from multiprocessing import Process, Queue def generator():c = 0while True:time.sleep(1.0) # read somethingyield cc += 1 %%timeds = generator() for i in range(3):item = next(ds)time.sleep(1.0) # do somethingprint(item) 0 1 2 CPU times: user 3.27 ms, sys: 456 μs, total: 3.73 ms Wall time: 6.01 s def kernel(func, q: Queue):ds = func()while True:item = next(ds)q.put(item) def multi_generator(func):q = Queue()p = Process(target=kernel, args=(func, q))p.start()while True:item = q.get()yield item在windows下運行這個單元格的話,會一直顯示在運行,
%%timeds = multi_generator(generator) for i in range(3):item = next(ds)time.sleep(1.0)print(item)錯誤
運行上面的代碼,后臺會報如下錯
解決方法
1、些處解決方案,是利用Windows 10 下的WSL的Linux系統解決的。
怎樣配置WSL,請參考鏈接https://blog.csdn.net/jasneik/article/details/123782018
直接打開Ubuntu 控制臺,運行jupyter notebook,一般不會像Windows下的會自動跳轉,可以把jupyter notebook含token的鏈接拷貝到瀏覽器打開。類似如下的鏈接
然后把上面的代碼拷,再運行,就OK了。
2、可以參考此方面,是把方法寫到臨時文件(我沒有試過)
https://blog.csdn.net/e274794140/article/details/87286190
總結
以上是生活随笔為你收集整理的Windows下 jupyter notebook 运行multiprocessing 报错的问题与解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 前端部分-JSON-对象转换为字符串
- 下一篇: java windows so文件_wi