> Thank you, add_rb_timer can work, but I get an error:
> [uwsgi-signal] you have registered this signal in worker 1 memory area,
> only that process will be able to run it Sun Apr 29 11:33:12 2012 - error
> managing signal 99 on worker 2
This is the expected behaviour, as if you register a signal handler in a
process you cannot expect another process will have acces to it.
You can force a signal to be delivered only to a specific worker with
uwsgi.register_signal(99, "worker1", functions.timer_test)
or (for automagic)
uwsgi.register_signal(99, "worker%d" uwsgi.worker_id(), functions.timer_test)
A better approach would be defining signal handler during startup (in your
wsgi file or in a module you can import with --import) and creating the
timer when (and where) you want.
For your specific case you can do something similar:
# decorate the function in functions.py
from uwsgidecorators import signal
@signal(99)
def timer_test(num):
....
And in your view simply call
uwsgi.add_rb_timer(99, 10, 1)
>
> Code:
> functions.py
> def send_html_mail(subject, html_content, recipient_list):
> msg = EmailMessage(subject, html_content, settings.EMAIL_HOST_USER,
> recipient_list)
> msg.content_subtype = "html" # Main content is now text/html
> msg.send()
>
> def timer_test(num):
> send_html_mail("test_timer", "<b>Work</b>", ["[email protected]"])
>
> views.py
> def index(request):
> #task.myspooler.spool(filename="/var/www/conf")
> uwsgi.register_signal(99, "", functions.timer_test)
> uwsgi.add_rb_timer(99, 10, 1)
> #functions.timer_test(10)
> return render_to_response("index.html", locals())
>
>
> ------------------ Original ------------------
> From: "Roberto De Ioris"<[email protected]>;
> Date: Sun, Apr 29, 2012 10:32 AM
> To: "uWSGI developers and users list"<[email protected]>;
>
> Subject: Re: [uWSGI] add_timer one-shot
>
>
>
>> Hi,
>>
>> I want to use one shot timer , but when I use uwsgi.add_timer(30, 40,
>> 1),
>> I get a exception:
>>
>>
>> TypeError at /
>> add_timer() takes exactly 2 arguments (3 given)
>>
>> Is this a bug or am I missing something?
>>
>> uwsgi virson == 1.1.2_______________________________________________
>> uWSGI mailing list
>> [email protected]
>> http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi
>>
>
>
> Oneshot timers are only available in redblack mode:
>
> uwsgi.add_rb_timer(signum, secs, iterations)
>
> set iterations = 1 to have a one-shot timer
>
> --
> Roberto De Ioris
> http://unbit.it
> _______________________________________________
> uWSGI mailing list
> [email protected]
> http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi_______________________________________________
> uWSGI mailing list
> [email protected]
> http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi
>
--
Roberto De Ioris
http://unbit.it
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi