Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non thread-safe code using threads #127

Open
rrbarbosa opened this issue Jan 11, 2021 · 2 comments
Open

Non thread-safe code using threads #127

rrbarbosa opened this issue Jan 11, 2021 · 2 comments

Comments

@rrbarbosa
Copy link

In the python implementation, the RecordAggregator class is annotated as "not thread-safe", however the class makes use of threading to execute the callback by default.

Won't this snippet end up clearing the record before executing the callback?

        # If we hit this point, aggregated record is full
        # Call all the callbacks (potentially on a separate thread)
        out_record = self.current_record
        for (callback, execute_on_new_thread) in self.callbacks:
            if execute_on_new_thread:
                threading.Thread(target=callback, args=(out_record,)).start()
            else:
                callback(out_record)
        
        # Current record is full so clear it out, make a new empty one and add the user record
        self.clear_record()

A simple workaround is stop using threading for callbacks.

@IanMeyers
Copy link
Contributor

I think actually that line 215 should instead use copy.deepcopy() rather than assignment. But in principle I agree that this is an issue. Will look to patch.

@IanMeyers
Copy link
Contributor

This is fixed in 85e8678 and version 1.1.4 on pypi

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

No branches or pull requests

2 participants