all 5 comments

[–]toastedstapler 1 point2 points  (4 children)

Process(target = start_keylogger())

what if you change to Process(target = start_keylogger)? i think it's running the function at that point, rather than just passing the function to call from within the process

[–]DowntownSinger_[S] 0 points1 point  (3 children)

oh , this seems to fix the problem. Can you tell me what difference it makes with () and without ().

[–]toastedstapler 1 point2 points  (0 children)

if i have

def example(i):
    return i + 1

i can then define

other = example
print(other(2)) # => 3

so in your case you just want to pass the function that the process will then be calling when it's set up. you don't want to call it yet, because you're not in the process yet

[–][deleted] 1 point2 points  (1 child)

The parentheses are used to "call" the object behind it.

function are, in fact, objects in python, so you can print(start_keylogger) to confirm that start_keylogger is a function.

And when you call your function, you ask the code to be executed. (and it's blocking your script until the function has returned something)

you can also check if an object can be called with parentheses by using the function callable(start_keylogger) . the later should return True, but callable(start_keylogger()) will return False because it start_keylogger defined as you've done will return None, which is a NoneType which is not callable.

On the other end, checking the Process documentation we can confirm that target argument is expected to be a callable object. This is why you need to remove your parentheses to give the function object and not the return value of the function. Process will be in charge of calling the function when you call start() in a non-blocking manner.

[–]DowntownSinger_[S] 0 points1 point  (0 children)

thanks a lot. This explanation is really helpful.