Monday, March 27, 2017

Re: Setup_environ before or after forking?

If you are still in need of a Django expert, have you checked out https://datepalm.engineering to see if they can help?

They are Django experts from what I understand, and based in the US.


On Wednesday, January 28, 2009 at 9:30:41 AM UTC+5, Malcolm Tredinnick wrote:
On Tue, 2009-01-27 at 12:56 -0800, Andrew Fong wrote:
[...]
> Question: Does it make more sense to call setup_environ before or
> after forking?

I'd do it after forking.
>
> In particular, I don't know how Django sets up its database
> connection.

A connection is created the first time you access a database and then
closed when the response is sent back (or, in standalone cases, when you
either explicitly close it or when the process ends).

> Do forked processes share one connection or does each
> process have their own connection?

The most precise answer is "it depends", but the simplest answer is that
they would be shared and it wouldn't behave as you expect. Don't do
that.  Forked processes share file descriptors, for example (well,
they're duplicated, not shared), so if the connection uses a file
descriptor, which it will, that is duplicated.

> Are there pros and cons to each?

Creating the connection after forking will work. Creating the connection
before forking will likely lead to lots of difficult to diagnose race
conditions and the like.

Regards,
Malcolm

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1c05bb2b-b1d8-4bbf-adaa-18b83bca044b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment