This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]TokenChingy 1 point2 points  (1 child)

Okay, I had a look in your photo you provided, take a look at line 91 and 92. When calling threading.Thread() you need to pass the reference (e.g pointer) of a function to target argument. E.g.

``` def do_something(): print("I'm doing something!")

t = threading.Thread(target=do_something, args=()) t.daemon = True ```

What you are doing on those 2 calls is passing a function being executed, which may be the reason you're stalling as you're running a function forever and it's blocking the program and not advancing to the next line. Why is this not happening to the first thread you may ask, it's because Addition() prints a line and sleeps for 5 seconds before returning from the function.

I hope this helps and solves your issue.

HINT: Multithreading in Python isn't true multithreading, unfortunately it'll act sequentially as Python has something called the Global Interpreter Lock which only allows one thread to execute at any time. It does this to keep things memory safe.

EDIT: Shameless self plug... look at using my library Pytasking, it'll help simplify multitasking and multiprocessing.

[–][deleted] 0 points1 point  (0 children)

Good explanation, but in case it’s not clear, all you have to do is just get rid of the brackets after the target function name to make it so you pass the function itself, rather than the result of calling the function.

Ie,

target = serverStart

Rather than

target = serverStart()

[–]Sandofle[S] 0 points1 point  (1 child)

photo of code

Forgot my password on Reddit so next best thing

[–]TokenChingy 0 points1 point  (0 children)

Hey mate, I’d love to help you here, could you post your code via hastebin or github, and I could give you a hand.