AssertionError when threading in Python

后端 未结 2 1798
再見小時候
再見小時候 2020-12-15 16:11

I\'m trying to run some simple threading in Python using:

t1 = threading.Thread(analysis(\"samplequery\"))
t1.start()

other code runs in here

t1.join()


        
相关标签:
2条回答
  • 2020-12-15 16:38

    You want to specify the target keyword parameter instead:

    t1 = threading.Thread(target=analysis("samplequery"))
    

    You probably meant to make analysis the run target, but 'samplequery the argument when started:

    t1 = threading.Thread(target=analysis, args=("samplequery",))
    

    The first parameter to Thread() is the group argument, and it currently only accepts None as the argument.

    From the threading.Thread() documentation:

    This constructor should always be called with keyword arguments. Arguments are:

    • group should be None; reserved for future extension when a ThreadGroup class is implemented.
    • target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.
    0 讨论(0)
  • 2020-12-15 16:46

    You need to provide the target attribute:

    t1 = threading.Thread(target = analysis, args = ('samplequery',))
    
    0 讨论(0)
提交回复
热议问题