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

Update styleguide about thd_ prefix for secondary-thread functions. #1350

Merged
merged 2 commits into from Nov 14, 2014

Conversation

benallard
Copy link
Contributor

No description provided.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It is very important in Twisted to be able to distinguish functions that runs in the main-thread and functions that don't, as reactors and deferreds can only be used in the main thread.
To make this distinction clearer, every functions meant to be started in a secondary thread should be prefixed with ``thd_``.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/should/must/

@benallard
Copy link
Contributor Author

Fixed, thanks for the quick review !

sa2ajj pushed a commit that referenced this pull request Nov 14, 2014
Update styleguide about thd_ prefix for secondary-thread functions.
@sa2ajj sa2ajj merged commit aa8ab90 into buildbot:master Nov 14, 2014
@benallard benallard deleted the patch-1 branch November 14, 2014 12:38
@gsemet
Copy link

gsemet commented Nov 15, 2014

I am curious about the reason of this distinction. Can you elaborate or point to a documentation telling why this distinction is so important?

@djmitche
Copy link
Member

@stibbons I think the core of it is in the new text itself: Twisted's reactor is intended to run in the main thread, and calling reactor methods in non-main threads causes weird and subtle bugs. Back in the 0.8.2 days, we had some functions that ran in threads but fired deferreds. The result was running callbacks for those deferreds in a thread other than the main thread, in parallel to other callbacks running in the main thread. Suddenly all of the data-safety you get from Twisted goes out the window, you get fun race conditions, corruption, and crashes.

Does that help?

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

Successfully merging this pull request may close these issues.

None yet

4 participants