Re: Managing a process from Django

2018-01-09 Thread Kasper Laudrup

Hi Antonis,

On 2018-01-09 07:14, Antonis Christofides wrote:

Ah, OK, sorry I didn't read all the discussion. So I guess that if you keep that
in a global variable, it won't work if your Django app is running in many
processes. (Besides, global variables are rarely a good idea.)



I agree completely that global variables should be avoided. I find them 
to be even more problematic in a language like python where they could 
be instatiated by simply importing a file/module. That's probably OK for 
a simple value like an integer, but I prefer imports not to have too 
many side effects.



If I understand the problem correctly, what I would do would probably be to
touch a file whenever I make a change and examine the file modification date
each time—if it's more recent than last time I checked, the data has been 
modified.

Another option is to use the cache. For example, use memcached and store some
data in there. IIRC the cache is shared among all instances of Django.



That's not really solving my problem, but thanks for your input. What I 
need is a "global" python popen object from the subprocess module.


Someone helpfully suggested using a singleton for that. I really don't 
like singletons either, but this could actually be one of the few use 
cases where that would make sense, so I think that's what I'll be doing.


Kind regards,

Kasper Laudrup

--
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+unsubscr...@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/6662fd12-af9f-0271-8bb7-4486e80faf90%40stacktrace.dk.
For more options, visit https://groups.google.com/d/optout.


Re: Managing a process from Django

2018-01-08 Thread Antonis Christofides
Ah, OK, sorry I didn't read all the discussion. So I guess that if you keep that
in a global variable, it won't work if your Django app is running in many
processes. (Besides, global variables are rarely a good idea.)

If I understand the problem correctly, what I would do would probably be to
touch a file whenever I make a change and examine the file modification date
each time—if it's more recent than last time I checked, the data has been 
modified.

Another option is to use the cache. For example, use memcached and store some
data in there. IIRC the cache is shared among all instances of Django.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com

On 2018-01-09 00:00, Kasper Laudrup wrote:
> Hi Antonis,
>
> On 2018-01-08 22:46, Antonis Christofides wrote:
>> OK, but why do you need this? What functionality is this going to have?
>>
>
> As I wrote in my original question, I'm attempting to write a Django
> application for managing DHCP leases and DNS entries.
>
> So, if a user changes an entry by modifying a model in Django, I need to
> update some external files and restart a process so the new files will be 
> reread.
>
> I might be approaching this the wrong way, but I would really like my Django
> application to "own" this process, so I would like a global instance of that
> which I could start/restart/kill from my Django application.
>
> I'm perfectly open for other ways to solve this, it just seemed like a fairly
> obvious way to do it, but I could very well be wrong.
>
> Thanks a lot and kind regards,
>
> Kasper Laudrup
>

-- 
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+unsubscr...@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/a504b4ac-1ee8-b39d-21a5-dc9042fef25e%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: Managing a process from Django

2018-01-08 Thread Kasper Laudrup

Hi Joakim,

On 2018-01-08 22:50, Joakim Hove wrote:
Sounds to me that what you want is a `singleton` implemented in Python . 
The fact that Django is involved does not seem to be very relevant?




Indeed, that has crossed my mind and I'm sorry if this is in fact not 
very Django related. But I'm wondering if it would be a nice design to 
simply have a .py file with a singleton class and then accessing that 
from wherever I need it, but thinking about it, then why not?


Sorry if I have created a lot of noise, but that actually seems like 
exactly what I want. I might have been trying to overengineer things 
instead of just keeping it simple :-)


Thanks a lot for all the help from everyone helping me with my not very 
specific questions.


Kind regards,

Kasper Laudrup

--
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+unsubscr...@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/5e49dd7b-222a-782e-b50f-958b0e1a535c%40stacktrace.dk.
For more options, visit https://groups.google.com/d/optout.


Re: Managing a process from Django

2018-01-08 Thread Kasper Laudrup

Hi Antonis,

On 2018-01-08 22:46, Antonis Christofides wrote:

OK, but why do you need this? What functionality is this going to have?



As I wrote in my original question, I'm attempting to write a Django 
application for managing DHCP leases and DNS entries.


So, if a user changes an entry by modifying a model in Django, I need to 
update some external files and restart a process so the new files will 
be reread.


I might be approaching this the wrong way, but I would really like my 
Django application to "own" this process, so I would like a global 
instance of that which I could start/restart/kill from my Django 
application.


I'm perfectly open for other ways to solve this, it just seemed like a 
fairly obvious way to do it, but I could very well be wrong.


Thanks a lot and kind regards,

Kasper Laudrup

--
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+unsubscr...@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/4b8dbfdc-27cf-2922-25c8-bf33f0dbf10e%40stacktrace.dk.
For more options, visit https://groups.google.com/d/optout.


Re: Managing a process from Django

2018-01-08 Thread Joakim Hove
Sounds to me that what you want is a `singleton` implemented in Python .
The fact that Django is involved does not seem to be very relevant?


8. jan. 2018 22:43 skrev "Kasper Laudrup" :

> Hi Antonis,
>
> On 2018-01-08 22:10, Antonis Christofides wrote:
>
>> Hello,
>>
>> When you say "call [an instance of an object]", what exactly do you mean?
>>
>>
> Sorry, I meant an instance of a class or just an object.
>
> Could you tell us more about what this class/object is and why you need to
>> "call" (access?) it in an unusual way?
>>
>>
> Nothing unusual about the class or object, sorry about the confusion.
>
> My question is probably fairly simple and I'm really sorry if there's
> something very basic that I'm missing.
>
> I want to create an instance of some class when the Django application I'm
> creating is ready (eg. by connecting to the ready() signal or similar) and
> then be able to call methods on that single instance from my models.
>
> Thanks a lot for the help so far.
>
> Kind regards,
>
> Kasper Laudrup
>
> --
> 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+unsubscr...@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/ms
> gid/django-users/bd87c994-77da-529b-1416-2e6d7a8d2aa5%40stacktrace.dk.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@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/CALKD1M8O8SLtfJK5cwj86x3Aad7T_45KdQAxMAYuUxSbfsEY0Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Managing a process from Django

2018-01-08 Thread Antonis Christofides
OK, but why do you need this? What functionality is this going to have?

Antonis Christofides
http://djangodeployment.com

On 2018-01-08 23:43, Kasper Laudrup wrote:
> Hi Antonis,
>
> On 2018-01-08 22:10, Antonis Christofides wrote:
>> Hello,
>>
>> When you say "call [an instance of an object]", what exactly do you mean?
>>
>
> Sorry, I meant an instance of a class or just an object.
>
>> Could you tell us more about what this class/object is and why you need to
>> "call" (access?) it in an unusual way?
>>
>
> Nothing unusual about the class or object, sorry about the confusion.
>
> My question is probably fairly simple and I'm really sorry if there's
> something very basic that I'm missing.
>
> I want to create an instance of some class when the Django application I'm
> creating is ready (eg. by connecting to the ready() signal or similar) and
> then be able to call methods on that single instance from my models.
>
> Thanks a lot for the help so far.
>
> Kind regards,
>
> Kasper Laudrup
>

-- 
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+unsubscr...@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/aca7b60d-3aa5-a711-8ab1-cb36a538895a%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: Managing a process from Django

2018-01-08 Thread Kasper Laudrup

Hi Antonis,

On 2018-01-08 22:10, Antonis Christofides wrote:

Hello,

When you say "call [an instance of an object]", what exactly do you mean?



Sorry, I meant an instance of a class or just an object.


Could you tell us more about what this class/object is and why you need to
"call" (access?) it in an unusual way?



Nothing unusual about the class or object, sorry about the confusion.

My question is probably fairly simple and I'm really sorry if there's 
something very basic that I'm missing.


I want to create an instance of some class when the Django application 
I'm creating is ready (eg. by connecting to the ready() signal or 
similar) and then be able to call methods on that single instance from 
my models.


Thanks a lot for the help so far.

Kind regards,

Kasper Laudrup

--
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+unsubscr...@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/bd87c994-77da-529b-1416-2e6d7a8d2aa5%40stacktrace.dk.
For more options, visit https://groups.google.com/d/optout.


Re: Managing a process from Django

2018-01-08 Thread Antonis Christofides
Hello,

When you say "call [an instance of an object]", what exactly do you mean?

Could you tell us more about what this class/object is and why you need to
"call" (access?) it in an unusual way?

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com


On 2018-01-08 22:02, Kasper Laudrup wrote:
> Hi again,
>
>>
>>     So my question is more related to any kind of process that should be
>>     managed from a Django app.
>>
>>
>> Django does not manages processes, Django is a web framework. Python can
>> manage processes. What kind? Any :)
>>
>
> I am fully aware of that, thank you :-)
>
> I guess my question is then actually more: if I would like to have one single
> instance of an object that I can call safely from models (or possibly views or
> whatever) where would be the right place to put that class and code?
>
> It seems like a fairly basic question, but I haven't found any obvious
> solution for that by reading the documentation, so maybe I'm just missing
> something basic? I must admit my experience with Django (although a good one)
> is fairly limited.
>
> Thanks a lot for your help so far.
>
> Kind regards,
>
> Kasper Laudrup
>

-- 
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+unsubscr...@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/374499b1-76b0-654a-92dd-e506523fc1a4%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: Managing a process from Django

2018-01-08 Thread Kasper Laudrup

Hi again,



So my question is more related to any kind of process that should be
managed from a Django app.


Django does not manages processes, Django is a web framework. Python can 
manage processes. What kind? Any :)




I am fully aware of that, thank you :-)

I guess my question is then actually more: if I would like to have one 
single instance of an object that I can call safely from models (or 
possibly views or whatever) where would be the right place to put that 
class and code?


It seems like a fairly basic question, but I haven't found any obvious 
solution for that by reading the documentation, so maybe I'm just 
missing something basic? I must admit my experience with Django 
(although a good one) is fairly limited.


Thanks a lot for your help so far.

Kind regards,

Kasper Laudrup

--
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+unsubscr...@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/d32507dc-3916-7cc3-10a9-8ea25926577d%40stacktrace.dk.
For more options, visit https://groups.google.com/d/optout.


Re: Managing a process from Django

2018-01-08 Thread Matemática A3K
On Mon, Jan 8, 2018 at 2:41 PM, Kasper Laudrup 
wrote:

> Hi Matemática A3K,
>
> On 2018-01-08 17:58, Matemática A3K wrote:
>
>>
>> With this https://stackoverflow.com/questions/89228/calling-an-externa
>> l-command-in-python
>> you can find out which distribution is using, then for each distribution
>> there's a different command for restarting DHCP (systemctl, upstart,
>> system-v) and with the same execute it with sudo to some user with
>> privileges to just do that. You can call that function ("restart_dhcp()")
>> from any django view.
>>
>>
> Thanks a lot for your answer.
>
> I would rather avoid using any kind of init system for managing dhcpd,
> since I would like to run the Django app in a docker container (running
> systemd inside docker is not a good idea) and the options given for eg.
> logging and configuration would be quite different from the standard
> installation of dhcpd on any distro.
>

Then it will be easier for you :)


>
> So my question is more related to any kind of process that should be
> managed from a Django app.
>
>
Django does not manages processes, Django is a web framework. Python can
manage processes. What kind? Any :)


> But thanks a lot for your input.
>
> Kind regards,
>
> Kasper Laudrup
>
> --
> 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+unsubscr...@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/ms
> gid/django-users/8325b598-5db5-2a34-8fc5-aa4c1daf0ad5%40stacktrace.dk.
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@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/CA%2BFDnh%2BeBKrh0p-a%2BEBxn%2B2NJm6Xj-vVs6Y_Ugjw7%2BQ9OabQsw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Managing a process from Django

2018-01-08 Thread Kasper Laudrup

Hi Matemática A3K,

On 2018-01-08 17:58, Matemática A3K wrote:


With this 
https://stackoverflow.com/questions/89228/calling-an-external-command-in-python
you can find out which distribution is using, then for each distribution 
there's a different command for restarting DHCP (systemctl, upstart, 
system-v) and with the same execute it with sudo to some user with 
privileges to just do that. You can call that function 
("restart_dhcp()") from any django view.




Thanks a lot for your answer.

I would rather avoid using any kind of init system for managing dhcpd, 
since I would like to run the Django app in a docker container (running 
systemd inside docker is not a good idea) and the options given for eg. 
logging and configuration would be quite different from the standard 
installation of dhcpd on any distro.


So my question is more related to any kind of process that should be 
managed from a Django app.


But thanks a lot for your input.

Kind regards,

Kasper Laudrup

--
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+unsubscr...@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/8325b598-5db5-2a34-8fc5-aa4c1daf0ad5%40stacktrace.dk.
For more options, visit https://groups.google.com/d/optout.


Re: Managing a process from Django

2018-01-08 Thread Matemática A3K
On Mon, Jan 8, 2018 at 12:48 PM, Kasper Laudrup 
wrote:

> Hi fellow Django users,
>
> I'm working on creating a Django application for managing DHCP leases and
> DNS entries and for that I would like to be able to (re)start the DHCP
> daemon from Djano.
>
> I think it would be best to simply use a popen object from pythons
> subprocess module (most likely wrapped in a class), but I'm not really sure
> which place would be the most logical place to keep that object? Of course
> there should only be a single instance of that object.
>
> I have also been looking into using some kind of service framework, but
> what I have found so far seems to be aimed at task queues (celery etc.),
> which would definitely be an overkill for my use case.
>
> It could also be that I'm approaching this the wrong way, in which case I
> would be happy to hear better ideas on how to do this.
>
> Thanks a lot for any input.
>
> Kind regards,
>
> Kasper Laudrup
>

With this
https://stackoverflow.com/questions/89228/calling-an-external-command-in-python
you can find out which distribution is using, then for each distribution
there's a different command for restarting DHCP (systemctl, upstart,
system-v) and with the same execute it with sudo to some user with
privileges to just do that. You can call that function ("restart_dhcp()")
from any django view.

HTH


>
> --
> 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+unsubscr...@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/ms
> gid/django-users/f86f877c-3462-b8bd-95ac-3da1c77c8f72%40stacktrace.dk.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@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/CA%2BFDnh%2Bpzu%3DE2yKHEkcPZhj8X3nA-29pwRfTo%3DSqk%2BOmjQUxkw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.