Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
threading
#1
Hi,

I have this code, which monitors folders for incoming files:

import os
import glob
import time
import threading
import smtplib

smtpserver = ''
smtpserverport = 587
fromaddress = ''
fromaddressusername = ''
fromaddresspassword = ''
toaddress = ''

class Sc:


    def __init__(self, name='Sc'):
        """ you may enter a name when instantiation"""
        self.name = name
        print('* ' * 3 + ' DAEMON STARTED' + ' *' * 3)
        print('[+] Instance name: ' + name)

    def getlastwav(self):
        pass

    def countfiles(self, folder):
        pass

    def sendmail(self, to):
        print('[+] email sent to ' + to)

    def checkfornewwav(self, folder='.',refresh=5):
        """ checks for new wav files, and sends email """
        print('[+] Folder to watch: ' + folder)
        print('[+] Refresh time: ' + str(refresh) + ' sec')
        while True:
            before = self.countfiles(folder)
            time.sleep(refresh)
            after = self.countfiles(folder)
            if before < after:
                print('[+] Last file: ' + self.getlastwav())
                self.sendmail('[email protected]')


threading.sc1 = Sc('first')
threading.sc1.checkfornewwav('.', 10)

threading.sc2 = Sc('second')
threading.sc2.checkfornewwav('.', 12)
I'd like the instantiations pop up in new terminal, moreover the second instantiation never gets instantiated this way.
Can you tell me how I could run such a daemon on different folders in different terminals with using CPU threading?

Thanks
Reply


Messages In This Thread
threading - by kerzol81 - Mar-12-2017, 01:46 PM
RE: threading - by Ofnuts - Mar-12-2017, 05:38 PM
RE: threading - by kerzol81 - Mar-13-2017, 04:45 PM
RE: threading - by Ofnuts - Mar-13-2017, 09:04 PM
RE: threading - by kerzol81 - Mar-14-2017, 09:23 AM
RE: threading - by wavic - Mar-13-2017, 09:15 PM
RE: threading - by Ofnuts - Mar-14-2017, 11:55 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Concurrent futures threading running at same speed as non-threading billykid999 13 2,015 May-03-2023, 08:22 AM
Last Post: billykid999
  Tutorials on sockets, threading and multi-threading? muzikman 2 2,166 Oct-01-2021, 08:32 PM
Last Post: muzikman

Forum Jump:

User Panel Messages

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