I know that a specific port can be given to cherrypy using
"server.socket_port" but I am wondering if there is a way to tell it to
pick up any available port (say, by passing 0 to the above option). I
tried this with 3.0RC1 but it tried to bind to 0 literally.
Any help is appreciated,
Raghu.
Christian
This can be handy when you share the system with others that run the
same application and allow for a safe callback in case your port is taken.
In any case this is a fairly handy feature, not critical but interesting
IMO :)
- Sylvain
I have a script that parses a log file and then starts cherrypy.
Another thread in the same script simply calls "webbrowser <url>" where
"url" will be processed by started cherrypy server. So the end result
is a command like this will bring up a nice browser interface to my log
file.
$ logutil.py -f <logfile> -p <port>
Right now, I will have to explicitly pass different ports if I run this
simultaneously. Since the consumer of the web page is internal to the
script itself, it will be nice if I can tell cherrypy to use whatever
port is available. If I can then query the port that is used to bind, I
can use that in my webbrowser invocation.
Basically, I am asking for something like this:
Python 2.4.2 (#1, May 2 2006, 08:13:46)
[GCC 4.1.0 (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> s = socket.socket()
>>> s.bind(("localhost", 0))
>>> s.getsockname()
('127.0.0.1', 40315)
On 1/15/07, raghu <drag...@gmail.com> wrote:
> I have a script that parses a log file and then starts cherrypy.
> Another thread in the same script simply calls "webbrowser <url>" where
> "url" will be processed by started cherrypy server.
[snip]
> Since the consumer of the web page is internal to the
> script itself, it will be nice if I can tell cherrypy to use whatever
> port is available. If I can then query the port that is used to bind, I
> can use that in my webbrowser invocation.
Ah, that makes complete sense. Maybe using the random stdlib module
to select a random port number and then using
cherrypy._cpserver.check_port would help?
Christian
It seems to me like wsgiserver should allow a port of 0 to mean "any
available port". But a quick look through the code doesn't explain why
that doesn't already work (since we don't even use the sa from
getaddrinfo for bind(); we use self.bind_addr instead).
Raghu, please open a ticket.
Robert Brewer
System Architect
Amor Ministries
fuma...@amor.org
-------------------------
File
"/localhome/raghu/localwork/cherrypy/svn.cherrypy.org/trunk/cherrypy/_cpserver.py",
line 69, in quickstart
self.start()
File
"/localhome/raghu/localwork/cherrypy/svn.cherrypy.org/trunk/cherrypy/_cpserver.py",
line 95, in start
self._start_http(httpserver)
File
"/localhome/raghu/localwork/cherrypy/svn.cherrypy.org/trunk/cherrypy/_cpserver.py",
line 118, in _start_http
self.wait(httpserver)
File
"/localhome/raghu/localwork/cherrypy/svn.cherrypy.org/trunk/cherrypy/_cpserver.py",
line 159, in wait
wait_for_occupied_port(*bind_addr)
File
"/localhome/raghu/localwork/cherrypy/svn.cherrypy.org/trunk/cherrypy/_cpserver.py",
line 247, in wait_for_occupied_port
raise IOError(msg)
IOError: Port 0 not bound on 'localhost'
-------------------------------------
I am trying to see if I can update self.bind_addr and if it makes any
difference. I am not very familiar with CP internals so this is a good
chance.
I will open a ticket.
Thanks,
Raghu.