Untitled

 avatar
unknown
plain_text
2 years ago
857 B
6
Indexable
import time
import queue
import threading
import os

def gui_process(q):
	file_to_monitor = 'file_to_monitor.txt'
	#other code
	q.put("new data!")

def process_notification(q):
	while True:
		message = q.get()
		print(message)

if __name__ == "__main__":
	q = queue.Queue()

	# Create and start the file monitoring thread.
	gui_thread= threading.Thread(target=gui_process, args=(q,))
	gui_thread.daemon = True
	gui_thread.start()

	# Create and start the notification processing thread.
	notification_thread = threading.Thread(target=process_notification, args=(q,))
	notification_thread.daemon = True
	notification_thread.start()

	try:
		# Keep the main thread running while the monitor_thread and notification_thread run in the background.
		while True:
			time.sleep(1)
	except KeyboardInterrupt:
		print("Exiting...")
Editor is loading...