AssertionError when threading in Python

PythonMultithreading

Python Problem Overview


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()

Unforunately I'm getting the error:

> "AssertionError: group argument must be none for now"

I've never implemented threading in Python before, so I'm a bit unsure as to what's going wrong. Does anyone have any idea what the problem is?

I'm not sure if it's relevant at all, but analysis is a method imported from another file.

I had one follow up query as well. Analysis returns a dictionary, how would I go about assigning that for use in the original method?

Thanks

Python Solutions


Solution 1 - Python

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.

Solution 2 - Python

You need to provide the target attribute:

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questiondjcmm476View Question on Stackoverflow
Solution 1 - PythonMartijn PietersView Answer on Stackoverflow
Solution 2 - Pythong.d.d.cView Answer on Stackoverflow