<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 線程和多處理 *版本0.13.0中的新功能。* ## 線程 雖然xlwings在技術上并不是線程安全的,但只要你至少擁有v0.13.0并堅持一個簡單的規則,它仍然很容易在線程中使用它:不要將xlwings對象傳遞給線程。 此規則不是macOS的要求,但如果您希望程序是跨平臺的,則仍建議使用此規則。 請參考下面的例子,它將**不**起作用: ~~~ import threading from queue import Queue import xlwings as xw num_threads = 4 def write_to_workbook(): while True: rng = q.get() rng.value = rng.address print(rng.address) q.task_done() q = Queue() for i in range(num_threads): t = threading.Thread(target=write_to_workbook) t.daemon = True t.start() for cell in ['A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9', 'A10']: # 這不起作用-將XLwings對象傳遞到線程將失敗! rng = xw.Book('Book1.xlsx').sheets[0].range(cell) q.put(rng) q.join() ~~~ 要使其工作,您只需要完全限定線程中的單元格引用,而不是傳遞`Book`對象: ~~~ import threading from queue import Queue import xlwings as xw num_threads = 4 def write_to_workbook(): while True: cell_ = q.get() xw.Book('Book1.xlsx').sheets[0].range(cell_).value = cell_ print(cell_) q.task_done() q = Queue() for i in range(num_threads): t = threading.Thread(target=write_to_workbook) t.daemon = True t.start() for cell in ['A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9', 'A10']: q.put(cell) q.join() ~~~ ## 多處理 >[info]注意 多處理僅在Windows上支持! 同樣的規則適用于多處理和線程,這是一個工作示例: ~~~ from multiprocessing import Pool import xlwings as xw def write_to_workbook(cell): xw.Book('Book1.xlsx').sheets[0].range(cell).value = cell print(cell) if __name__ == '__main__': with Pool(4) as p: p.map(write_to_workbook, ['A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9', 'A10']) ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看