Perform final parse after termination trigger set#192
Merged
Conversation
Contributor
Author
|
@kzscisoft can use this script to test functionality: from multiparser import FileMonitor
import csv
import threading
import time
import multiprocessing
import multiparser.parsing.tail as mp_tail_parser
import pathlib
fieldnames = ['number']
TRIGGER = multiprocessing.Event()
def write_rows():
pathlib.Path("results.csv").unlink(missing_ok=True)
with open("results.csv", "w") as file:
# Create a DictWriter object
writer = csv.DictWriter(file, fieldnames=fieldnames)
# Write the header row
writer.writeheader()
for i in range(50):
# Write data rows
writer.writerow({"number": i})
file.flush()
time.sleep(0.1)
TRIGGER.set()
def callback(data: dict, *_):
print(data)
time.sleep(0.5)
thread = threading.Thread(target=write_rows)
thread.start()
with FileMonitor(termination_trigger=TRIGGER) as monitor:
monitor.tail(
path_glob_exprs="results.csv",
parser_func=mp_tail_parser.record_csv,
callback=callback,
)
monitor.run() |
Member
|
@wk9874 tests are failing so I cannot merge this. |
…rser into wk9874/final_parse
kzscisoft
approved these changes
Jan 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Summary
If there is a long running callback, and the final lines of a results file are written while the callback is being executed and the termination trigger is called, then when the callback finishes it will stop the thread loop and never parse these final lines.
This change makes it so that after the termination trigger is set, the thread does one final loop to check for any final lines in the file, before exiting.
Hopefully will fix #155
✅ Checks
docswhere appropriate.