-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession_memory.py
More file actions
48 lines (40 loc) · 1.53 KB
/
Copy pathsession_memory.py
File metadata and controls
48 lines (40 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from concurrent.futures import ThreadPoolExecutor
import threading
import atexit
import time
from threading import Thread
# Initialize the ThreadPoolExecutor
executor = ThreadPoolExecutor(max_workers=4) # Adjust max_workers based on your system's capabilities
def create_embedding(files):
# Dummy function for creating embeddings
# Implement your file processing logic here
print("embedding procees is started")
time.sleep(10)
return(f"Processing files {files}")
# Simulate some work
def on_completion(future):
try:
result = future.result()
print("Task completed successfully with result:", result)
except Exception as exc:
print(f"Task generated an exception: {exc}")
def start_embedding_process():
# Example file processing and folder path
files = "hello_worls"
# Submit the embedding task to the thread pool
future = executor.submit(create_embedding, files)
future.add_done_callback(on_completion)
print("hello world")
return
# Optionally handle the result or exceptions from the task
try:
result = future.result() # Waits for the thread to complete and returns the result
print("Task completed successfully:", result)
except Exception as exc:
print(f"Task generated an exception: {exc}")
# Optionally handle the result or exceptions from the task
# This ensures the executor shuts down properly when the program exits
atexit.register(executor.shutdown)
# Example usage
if __name__ == '__main__':
start_embedding_process()