Threading in python doesn't happen parallel

前端 未结 2 1327
孤街浪徒
孤街浪徒 2020-12-04 01:28

I\'m doing data scraping calls with an urllib2, yet they each take around 1 seconds to complete. I was trying to test if I could multi-thread the URL-call loop into threadin

2条回答
  •  生来不讨喜
    2020-12-04 02:02

    Paul Seeb has correctly diagnosed your issue.

    You are calling trade.update_items, and then passing the result to the threading.Thread constructor. Thus, you get serial behavior: your threads don't do any work, and the creation of each one is delayed until the update_items call returns.

    The correct form is threading.Thread(target=trade.update_items, args=(1, 100) for the first line, and similarly for the later ones. This will pass the update_items function as the thread entry point, and the *[1, 100] as its positional arguments.

提交回复
热议问题