Django

Code

Ticket #7676 (closed: fixed)

Opened 5 months ago

Last modified 4 months ago

django serializers are not thread safe!

Reported by: sector119 Assigned to: nobody
Milestone: 1.0 Component: Serialization
Version: SVN Keywords:
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

HI All!

I have to deserialize, serialize objects in multiple threads with django serializers.

But when I run Deserializer = serializers.get_deserializer(SERIALIZATION_FORMAT) in my threads (more then one, with _one_ thread all works great) I get KeyError?? in get_serializer function at return _serializers[format].Deserializer line because _load_serializers does not load all data at _serializers dict before another tread run get_deserializer at this another thread and completely populate serializers dictionary with all, builtin and user-defined serializers! That is why I think that get_(de)?serializers and/or _load_serializers must be thread safe like _populate function at AppCache??!

Attachments

threadsafe_serializers.diff (1.3 kB) - added by mrts on 07/08/08 08:28:37.
Threadsafe initialization of the _serializers dict
threadsafe_serializers-same_public_api.diff (3.0 kB) - added by mrts on 07/09/08 04:31:23.
Don't break the public API and be explicit about what is and is not thread-safe.

Change History

07/08/08 08:28:37 changed by mrts

  • attachment threadsafe_serializers.diff added.

Threadsafe initialization of the _serializers dict

07/08/08 08:29:33 changed by mrts

  • needs_better_patch changed.
  • has_patch set to 1.
  • needs_tests changed.
  • needs_docs changed.

sector119, please test if this fixes the problem.

07/08/08 09:01:30 changed by sector119

Thanks! It works fine for me!

07/08/08 09:02:58 changed by sector119

but why not use threading's RLock, acquire, release ?

07/08/08 09:43:59 changed by mrts

Locking is expensive and should be avoided if possible.

07/08/08 09:48:44 changed by mrts

  • component changed from Uncategorized to Serialization.
  • milestone set to 1.0.

As this is a bug, I'd assume it's in scope for 1.0.

07/09/08 04:31:23 changed by mrts

  • attachment threadsafe_serializers-same_public_api.diff added.

Don't break the public API and be explicit about what is and is not thread-safe.

07/13/08 10:53:51 changed by serialx

  • stage changed from Unreviewed to Accepted.

Looks Good To Me.

08/15/08 06:54:38 changed by russellm

  • status changed from new to closed.
  • resolution set to fixed.

(In [8370]) Fixed #7676 -- Modified serializer registration to be thread safe. Thanks to mrts for the patch.


Add/Change #7676 (django serializers are not thread safe!)




Change Properties
Action