Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #84596 > unrolled thread

HTTP over Asynchronous AF_UNIX Socket in python

Started byNorah Jones <nh.jones01@gmail.com>
First post2015-01-26 13:32 +0000
Last post2015-01-26 16:12 +0200
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  HTTP over Asynchronous AF_UNIX Socket in python Norah Jones <nh.jones01@gmail.com> - 2015-01-26 13:32 +0000
    Re: HTTP over Asynchronous AF_UNIX Socket in python Marko Rauhamaa <marko@pacujo.net> - 2015-01-26 16:12 +0200

#84596 — HTTP over Asynchronous AF_UNIX Socket in python

FromNorah Jones <nh.jones01@gmail.com>
Date2015-01-26 13:32 +0000
SubjectHTTP over Asynchronous AF_UNIX Socket in python
Message-ID<mailman.18146.1422279152.18130.python-list@python.org>
Hi, 

The problem description:

There are set of processes running on my system say `process_set_1`. Build a process agent which runs an `asynchronous` socket listening to incoming requests from process_set_1. Each process sends an `id`. The agent stores these ids in a dictionary and sends response that ur id has been accepted. Now agent process receives some data from another process (which is some sort of sister process for the agent). This data contains id along with a command which is to be sent by the agent to the process_set_1 through HTTP client over `AF_UNIX` socket, since each process in process_set_1 has a HTTP listening CLI. The process agent sends an HTTP request by recognizing id stored in dictionary to the process_set_1. A service running in the process_set_1 routes this HTTP command to the respective process.

Now my problem is the HTTP request which to be sent must go through AF_UNIX socket. I got this solution.

    class UnixStreamHTTPConnection(httplib.HTTPConnection):
    
        def __init__(self, path, host='localhost/rg_cli',port=None, strict=None,
                     timeout=None):
            httplib.HTTPConnection.__init__(self, host, port=port, strict=strict,
                                            timeout=timeout)
            self.path=path
    
        def connect(self):
            self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
            self.sock.connect(self.path)

But this cannot work since normal socket will not work and thus i thought of `asyncore` module in python. To use asyncore module again i will have to subclass asyncore.dispatcher. This class also contains connect() method.

Another problem is I don't know how asyncore module works and thus not able to find a way to mix the work of 1) listening forever, accept the connection, store id and the sock_fd. 
2) accept data from the process' agent sister process, retrieve the sock_fd by matching the id in the dictionary and send it through the AF_UNIX socket.

Please help since i have already spent 2 days digging it out. Sorry if could explain my problem very well.

Thanks,
Norah Jones

[toc] | [next] | [standalone]


#84601

FromMarko Rauhamaa <marko@pacujo.net>
Date2015-01-26 16:12 +0200
Message-ID<87siexeimb.fsf@elektro.pacujo.net>
In reply to#84596
Norah Jones <nh.jones01@gmail.com>:

> But this cannot work since normal socket will not work and thus i
> thought of `asyncore` module in python. To use asyncore module again i
> will have to subclass asyncore.dispatcher. This class also contains
> connect() method.
>
> Another problem is I don't know how asyncore module works and thus not
> able to find a way to mix the work of 1) listening forever, accept the
> connection, store id and the sock_fd.
> 2) accept data from the process' agent sister process, retrieve the
> sock_fd by matching the id in the dictionary and send it through the
> AF_UNIX socket.

Asyncore was a nice idea, but you shouldn't build anything on top of it.
The newest Python versions have moved to a scheme called asyncio. Its
programming model is a bit unconventional and hasn't won me over yet.

Personally, I have found select.epoll(EPOLLET) plus a timer
implementation enough of a framework for all of my async needs.

Then comes HTTP support. The stdlib networking facilities are great for
quick scripting, but not really compatible with the asynchronous
paradigm. I have coded my protocols by hand myself.


Marko

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web