Skip to content

Fix race condition in batch_predict by replacing file-based processing with in-memory DataFrame#92

Open
BHUVANA-SANKU24 wants to merge 2 commits intoruxailab:mainfrom
BHUVANA-SANKU24:fix/batch-predict-inmemory
Open

Fix race condition in batch_predict by replacing file-based processing with in-memory DataFrame#92
BHUVANA-SANKU24 wants to merge 2 commits intoruxailab:mainfrom
BHUVANA-SANKU24:fix/batch-predict-inmemory

Conversation

@BHUVANA-SANKU24
Copy link
Copy Markdown

Summary

This PR fixes the race condition in the /api/session/batch_predict endpoint by replacing file-based intermediate storage with in-memory processing using pandas DataFrames.


Problem

The previous implementation used a temporary CSV file (temp_batch_predict.csv) to pass prediction data. This caused:

  • Race conditions under concurrent requests
  • File I/O overhead affecting performance
  • Potential file conflicts in multi-user scenarios

Solution

  • Replaced temporary CSV-based workflow with in-memory pandas DataFrame (df_predict)
  • Updated predict_new_data_simple to accept DataFrame input instead of file path
  • Removed unnecessary file writing logic

Additional Improvements

  • Removed debug print statements for cleaner production code
  • Simplified route handling in main.py by delegating logic to session.py
  • Cleaned up redundant and dead code

Testing

  • Tested /health endpoint
  • Tested /api/session/batch_predict using curl
  • Verified correct prediction outputs
  • Confirmed no file creation and stable behavior across repeated requests

Related Issue

Fixes #82


Notes

Happy to align with existing approaches if maintainers prefer a different design direction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Race Condition: Shared temp file in batch_predict() causes incorrect gaze predictions

1 participant