Python Forum
Working with Threads - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Working with Threads (/thread-32291.html)



Working with Threads - Gilush - Feb-02-2021

Hi all,

So I have this small program that does multiple actions:
  • Mouse - Captures mouse location.
  • Capture system information to file.
  • Keylogger - logging keyboard presses and save to file.
  • Screenshot - Taking a full screenshot and save to file.
  • Upload - Uploads dir content to FTP every n time.
i'm trying to condition all the above under the Mouse thread so if it stops - everything stops.
I'm struggeling with terminating the thread with "when" condition or "if" condition but I still get 2 threads running infintly.

this is the output I get (no errors):

Quote:| Mouse: False | Screen: True | Keylogger: True | Upload: False
| Mouse: False | Screen: True | Keylogger: True | Upload: False
| Mouse: False | Screen: True | Keylogger: True | Upload: False
| Mouse: False | Screen: True | Keylogger: True | Upload: False
| Mouse: False | Screen: True | Keylogger: True | Upload: False
| Mouse: False | Screen: True | Keylogger: True | Upload: False
| Mouse: False | Screen: True | Keylogger: True | Upload: False

Process finished with exit code -1


EDIT: Problem solved.


RE: Working with Threads - nilamo - Feb-03-2021

Quote:EDIT: Problem solved.
For anyone stumbling upon this in the future, I recommend using a simple Event object. The long-running threads can just check if event.is_set(), and when you want them all to stop, you set it, so they know to stop: event.set(). The Event object will handle all the details for you to make it thread safe.
https://docs.python.org/3/library/threading.html#event-objects


RE: Working with Threads - Gilush - Feb-04-2021

That is exactly the solution I used in my code.
(since the code is an offensive cyber oriented project I removed it from the post.)

Should have posted the solution though.. thanks for posting it!