Skip to content

Thread-safety in Async Worker #1122

Answered by miguelgrinberg
Bi0max asked this question in Q&A
Discussion options

You must be logged in to vote

In general I'd say the answer is yes for 1 and no for 2.

But really you need to look at this in detail to determine exactly when you need to lock. Given that you are using a message queue, the first consideration is wether the writes to the message queue are safe to issue from multiple tasks. If they are, then the emits from your background jobs should be safe as well.

If your server will never have two background jobs emitting at the same time, then this is also a good indicator that you can get away without using locks.

The external workers should be fine as long as they don't emit from multiple tasks.

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@Bi0max
Comment options

@miguelgrinberg
Comment options

@Bi0max
Comment options

@miguelgrinberg
Comment options

@Bi0max
Comment options

Answer selected by Bi0max
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants