summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHui Lan <lanhui@zjnu.edu.cn>2025-03-09 18:09:39 +0800
committerHui Lan <lanhui@zjnu.edu.cn>2025-03-09 18:09:39 +0800
commitf4a6890da020ddf31e77451949b2f91b90666acb (patch)
treeec61e26a0bbce9ba4aa43257e0d24cf46fddd030
parentd47bfb5da360ac675b335d169c49f42f272038d5 (diff)
Kill wget if it takes too long
-rw-r--r--Code/download_and_map.py14
-rw-r--r--Code/killprocess.py14
2 files changed, 27 insertions, 1 deletions
diff --git a/Code/download_and_map.py b/Code/download_and_map.py
index bc1c190..ebc742d 100644
--- a/Code/download_and_map.py
+++ b/Code/download_and_map.py
@@ -15,7 +15,7 @@
# Last reviewed 31 July 2018
# Last revised 10 Feb 2021
-import os, sys, glob, json
+import os, signal, sys, glob, json
import fnmatch
import time
import re
@@ -349,6 +349,17 @@ def read_run_ids_from_file(fname):
return list(set(lst))
+def kill_process(process_name):
+ try:
+ for line in os.popen('ps ax | grep ' + process_name + ' | grep -v grep'):
+ fields = line.split()
+ if fields[4] == process_name:
+ pid = fields[0]
+ os.kill(int(pid), signal.SIGKILL)
+ return True
+ except Exception as e:
+ print(f'{e}')
+ return False
## main
@@ -370,6 +381,7 @@ if not last_session_finished(DOWNLOADED_SRA_ID_LOG_FILE): # last session not fin
write_network_log_file(s, UPDATE_NETWORK_LOG_FILE)
if age_of_file_in_hours(DOWNLOADED_SRA_ID_LOG_FILE) > 24: # add DONE to the log file anyway
append_done(DOWNLOADED_SRA_ID_LOG_FILE)
+ kill_process('wget')
sys.exit()
rna_data_info_dict = read_ena_data_info_json(RNA_SEQ_INFO_FILE) # rna_data_info_dict contains only RNA-seq IDs.
diff --git a/Code/killprocess.py b/Code/killprocess.py
new file mode 100644
index 0000000..d2237aa
--- /dev/null
+++ b/Code/killprocess.py
@@ -0,0 +1,14 @@
+import os, signal
+def kill_process(process_name):
+ try:
+ for line in os.popen('ps ax | grep ' + process_name + ' | grep -v grep'):
+ fields = line.split()
+ if fields[4] == process_name:
+ pid = fields[0]
+ os.kill(int(pid), signal.SIGKILL)
+ return True
+ except Exception as e:
+ print(f'{e}')
+ return False
+
+kill_process('sleep')