Browse Source

ignore files having a handle

test_without_lockfile
Dirk Alders 1 year ago
parent
commit
faae45b030
1 changed files with 14 additions and 1 deletions
  1. 14
    1
      file2mail.py

+ 14
- 1
file2mail.py View File

6
 import logging
6
 import logging
7
 import mail
7
 import mail
8
 import os
8
 import os
9
+import psutil
9
 import report
10
 import report
10
 import time
11
 import time
11
 
12
 
16
 report.stdoutLoggingConfigure(log_name_lvl=[('root', config.LOG_LEVEL), ])
17
 report.stdoutLoggingConfigure(log_name_lvl=[('root', config.LOG_LEVEL), ])
17
 
18
 
18
 
19
 
20
+def has_handle(fpath):
21
+    for proc in psutil.process_iter():
22
+        try:
23
+            for item in proc.open_files():
24
+                if fpath == item.path:
25
+                    return True
26
+        except Exception:
27
+            pass
28
+
29
+    return False
30
+
31
+
19
 if __name__ == "__main__":
32
 if __name__ == "__main__":
20
     while True:
33
     while True:
21
         # Check if LOCK_FILE EXISTS
34
         # Check if LOCK_FILE EXISTS
32
                 # Scan for files to send
45
                 # Scan for files to send
33
                 for filename in fstools.filelist(config.TARGET_FOLDER):
46
                 for filename in fstools.filelist(config.TARGET_FOLDER):
34
                     # Exclude LOCK_FILE
47
                     # Exclude LOCK_FILE
35
-                    if filename != LOCK_FILE:
48
+                    if filename != LOCK_FILE and not has_handle(filename):
36
                         logger.info("Found %s to send via E-Mail to %s.", filename, config.SEND_TO)
49
                         logger.info("Found %s to send via E-Mail to %s.", filename, config.SEND_TO)
37
                         # Send File as E-Mail
50
                         # Send File as E-Mail
38
                         try:
51
                         try:

Loading…
Cancel
Save