Python Forum

Full Version: Working with Threads
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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/thread...nt-objects
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!