完整代碼:
from code import InteractiveConsole
from turtle import position
import cv2 as cv
from time import time
from windowcapture import WindowCapture
from vision import Vision
import pyautogui
from paths import Products
from time import sleep
from functions import click
from threading import Thread
def do_Collect(self, cord_produto=None, produto=None):
bot_running = True
print(produto)
print(type(produto))
if produto == 'trigo':
bot_status = produto
for cord in cord_produto:
offset_x = 0
offset_y = 0
cord_x = cord[0] offset_x
cord_y = cord[1] offset_y
print(f' Colhendo {produto} nas cordenadas: {cord}')
print(f'Quantidade de cordadenas encontradas {len(cord_produto)}')
click(cord_x , cord_y)
sleep(2)
# else:
# raise Exception('!Exce??o! Produto: {produto} e Cordenadas: {cord_produto}')
bot_running = False
bot_status = None
###
while(True):
screenshot = wincap.get_screenshot() #PyAutoGui Tira o ScreenShot
positions_trigo = vision_Trigo.find(screenshot, 0.6, 'rectangles')
###
#Bot Commands Call
if not bot_running:
print('bot parado')
if len(positions_trigo):
trigo = 'trigo'
t = Thread(target=do_Collect, args=(positions_trigo, trigo))
t.start()
positions_trigo = ''
###
#Print FPS
print('FPS: {}'.format(1/(time()-loop_time)))
loop_time = time()
#Wait Key Q
if cv.waitKey(1) == ord('q'): #Espera a tecla Q ser apertada para sair
cv.destroyAllWindows()
break
print('Programa Finalizado')
在 Thread 函式內的“trigo”上是我的問題。我正在嘗試將超過 1 個引數從執行緒傳遞給函式 *args。
t = Thread(target=do_Collect, args=(positions_trigo, trigo)) #Does not work
如果我沒有“trigo”,它會起作用。
t = Thread(target=do_Collect, args=(positions_trigo,)) #Work
當我測驗我的可呼叫函式的變數時,我只收到標準值“無”。所以下面的函式永遠不是 True。
def do_Collect(self, cord_produto=None, produto=None):
bot_running = True
print(produto)
print(type(produto))
if produto == 'trigo': #always false
我需要什么來糾正這個?
uj5u.com熱心網友回復:
您的方法宣告包含 a self,但它不包含在類中。如果您洗掉它可能會起作用self。
下次請創建一個MRE,即用最少的代碼重現問題的示例,如下所示:
def do_Collect(self, cord_produto=None, produto=None):
print(cord_produto, produto)
from threading import Thread
t = Thread(target=do_Collect, args=("a", "b"))
t.start()
t.join()
洗掉self它就可以了。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/430562.html
標籤:Python 多线程 python-多线程
