Re: Bad file descriptor when sending message several times

43 views
Skip to first unread message

David Siroky

unread,
Jul 14, 2013, 4:49:21 AM7/14/13
to sna...@googlegroups.com
Hi!

It looks like the schedule_task() method is called more times in parallel. Since
the link object is present the whole time (class attribute) it can do nasty
things. I'm actually surprised that it works sometimes because cleanup() closes
the poll bell and it can't serve any other requests.

Better way is to create the whole snakeMQ stack (link-packeter-messaging) once
and run the loop in a thread without stopping after every message.

David

On 5.7.2013 17:17, sysedit wrote:
> Hi,
>
> I'm using snakeMQ to have communication between a Django app and a scheduling server (using AP Scheduler). In a given view, I'm sending a message and the server will create scheduled tasks.
>
> This works pretty well, except if requests are coming very fast ; in that case I get:
>
>
> Traceback (most recent call last):
> File "/python/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
> response = callback(request, *callback_args, **callback_kwargs)
> File "/python/lib/python2.7/site-packages/django/views/generic/base.py", line 48, in view
> return self.dispatch(request, *args, **kwargs)
> File "/python/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 77, in wrapped_view
> return view_func(*args, **kwargs)
> File "/python/lib/python2.7/site-packages/djangorestframework-2.2.1-py2.7.egg/rest_framework/views.py", line 393, in dispatch
> response = self.handle_exception(exc)
> File "/python/lib/python2.7/site-packages/djangorestframework-2.2.1-py2.7.egg/rest_framework/views.py", line 390, in dispatch
> response = handler(request, *args, **kwargs)
> File "/django/inventory/views/notifications_view.py", line 33, in post
> data=request.DATA['data']
> File "/django/inventory/notifications/scheduler.py", line 37, in schedule_task
> m.send_message("fw_server", msg)
> File "/python/lib/python2.7/site-packages/snakeMQ-1.1-py2.7.egg/snakemq/messaging.py", line 346, in send_message
> self.packeter.link.wakeup_poll()
> File "/python/lib/python2.7/site-packages/snakeMQ-1.1-py2.7.egg/snakemq/link.py", line 362, in wakeup_poll
> self._poll_bell.write(b"a")
> File "/python/lib/python2.7/site-packages/snakeMQ-1.1-py2.7.egg/snakemq/pollbell.py", line 42, in write
> os.write(self.w, buf)
> OSError: [Errno 9] Bad file descriptor
>
> I'm using the following class to send messages to the server:
>
> class MessageClientScheduler(object):
>
> link = snakemq.link.Link()
> sent = False
>
> def msg_sent(self,conn, ident, message):
> self.sent = True
> self.link.stop()
>
>
> def schedule_task(self, type, schedule, name, url, data):
> self.sent = False
> data = {
> 'action':0, #add action
> 'type': type,
> 'url': url,
> 'data' : data,
> 'schedule' : schedule,
> 'name' : name,
> }
>
> self.link.add_connector(("localhost", 4000))
> pktr = snakemq.packeter.Packeter(self.link)
> m = snakemq.messaging.Messaging("django_client", "", pktr)
> m.on_message_sent = self.msg_sent
> msg = snakemq.message.Message(pickle.dumps(data), ttl=60)
> m.send_message("server", msg)
> self.link.loop(runtime=5)
> self.link.cleanup()
>
>
> I'm stopping the loop when the message has been sent to not block the django app flow - not sure if this is ok, but seems to work.
>
> I configured the server side as follow:
> class MessageServer(object):
>
> @classmethod
> def on_recv(cls, conn, ident, message):
> print "MessageServer : on_recv"
> ...
>
> def start(self):
> link = snakemq.link.Link()
> link.add_listener(("localhost", 4000))
> pktr = snakemq.packeter.Packeter(link)
> m = snakemq.messaging.Messaging("server", "", pktr)
> m.on_message_recv.add(MessageServer.on_recv)
> link.loop()
>
> m = MessageServer()
> m.start()
>
> Cleanup() is called, so I expect everything to be cleaned correctly.
> I tried to figure out what's wrong without success... any help would be welcome.
> Many thanks, and thanks for your work !
>
>
>
>
>
Reply all
Reply to author
Forward
0 new messages