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
In fact, a Python process cannot run threads in parallel but it can run them concurrently through context switching during I/O bound operations. This limitation is actually enforced by GIL. The Python Global Interpreter Lock (GIL) prevents threads within the same process to be executed at the same time.
A mutex lock can be used to ensure that only one thread at a time executes a critical section of code at a time, while all other threads trying to execute the same code must wait until the currently executing thread is finished with the critical section and releases the lock.
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 aThreadGroup
class is implemented.- target is the callable object to be invoked by the
run()
method. Defaults toNone
, meaning nothing is called.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With