Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Working with Threads
#1
Thumbs Up 
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.
Reply
#2
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
Gribouillis likes this post
Reply
#3
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!
nilamo likes this post
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020