May-24-2018, 05:23 AM
Hi,
I had a python script that searches for an item in a list.
Now my requirement is to start a separate thread for each item search in the for loop.
How can I achieve this?
Please help
I had a python script that searches for an item in a list.
Now my requirement is to start a separate thread for each item search in the for loop.
How can I achieve this?
Please help
import glob import os import csv patterns = ['ACM','ACX','AW','BC'] for pattern in patterns: base_path = '/ai2/data/dev/admin/inf/*{}*' search_path = base_path.format(pattern) for f in glob.glob(search_path): print("-----------------------") print ("The directory path is:") print f print("List of files in the directory are:") os.chdir('/ai2/data/dev/admin/inf/') os.chdir(f) cwd = os.getcwd() for subdir, dirs, files in os.walk(cwd, topdown=True): for file23 in glob.glob('*.err'): print file23In the above script for every "pattern" value, I need to start a separate thread
Output:[root@edgenod]# python p123.py
-----------------------
The directory path is:
/ai2/data/dev/admin/inf/inf_ACM_pvt
List of files in the directory are:
dsplit.err
-----------------------
The directory path is:
/ai2/data/dev/admin/inf/inf_ACX_pvt
List of files in the directory are:
accountshighfocus.err
acm_access_log.err
-----------------------
The directory path is:
/ai2/data/dev/admin/inf/inf_AW_pvt
List of files in the directory are:
aware.err
-----------------------
The directory path is:
/ai2/data/dev/admin/inf/inf_BC_pvt
List of files in the directory are:
run_ingest_BC_daily_1249.err