Hi, Roberto.
Apologies for the delay. I tried your example with my existing
configuration options; when it didn't work, I tried with a barebones
configuration, and I realised that it starts failing when I add the
thunder-lock option - not sure whether that's expected?

I'll be going through the "Thundering Herd" docs page to figure out whether
I really need thunder-lock (it was already there when I joined the project,
so I need to ask around for the rationale).

For reference, this is the working configuration:

[uwsgi]
chdir = /project-folder/
home = /project-virtualenv-folder

http = :5000

master = true
workers = 2
enable-threads

pidfile = /tmp/uwsgitemp.pid

shared-import = signals.py
mule = mule.py

Adding thunder-lock breaks the functionality (namely, only one worker
manages the signal, instead of both). This is on MacOS X 10.11.6.


Il giorno lun 3 ott 2016 alle ore 07:13 Roberto De Ioris <robe...@unbit.it>
ha scritto:

>
> > Hi, there.
> > I was trying to use uWSGI signals to communicate between a programmed
> mule
> > and the app's workers.
> > I assumed that if the mule sent uwsgi.signal(MY_NUMBER, 'workers') then
> my
> > handler would be executed once per worker. However, most of the time it's
> > only executed once (I have two workers). Only *sometimes* both workers
> > actually run the handler (the mule sleeps for a few seconds and then
> sends
> > the signal again, some iterations work, some don't).
> >
> > I also tried registering different signals to different workers (still
> > using the same handler); same result.
> > i.e. I tried using (in a separate module loaded through shared-import):
> >
> > uwsgi.register_signal(1, 'workers', my_handler)
> >
> > or
> >
> > uwsgi.register_signal(1, 'worker1', my_handler)
> > uwsgi.register_signal(2, 'worker2', my_handler)
> >
> > or annotating the handler with
> >
> > @signal(1, target='workers')
> >
> > No dice. I also tried sending the signal from the shared module instead
> of
> > the mule, still same result.
> > Am I misunderstanding something?
> >
> > (uWSGI 2.0.13.1, Python 2.7, OS X 10.11)
> >
> > Thanks in advance,
> >
> > Angelo
> > _______________________________________________
> > uWSGI mailing list
> > uWSGI@lists.unbit.it
> > http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi
> >
>
>
> Hi, the right (low-level) procedure would be:
>
> # register a signal that must be delivered to all workers (in a shared
> imported module):
>
> uwsgi.register_signal(num, 'workers', callable)
>
>
> Then in your mule simply raise:
>
> uwsgi.signal(num)
>
> Can you try with a super simple example:
>
> # the shared module
> import uwsgi
>
> def hello(signum):
>     print('Hello from worker %d' % uwsgi.worker_id())
>
> uwsgi.register_signal(1, 'workers', hello)
>
>
>
> # the mule
> mport uwsgi
> import time
>
> while True:
>     time.sleep(1)
>     uwsgi.signal(1)
>
> --
> Roberto De Ioris
> http://unbit.com
> _______________________________________________
> uWSGI mailing list
> uWSGI@lists.unbit.it
> http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi
>
_______________________________________________
uWSGI mailing list
uWSGI@lists.unbit.it
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to