Pavion / tvstreamrecord

Timed TV stream recording for Python
GNU General Public License v3.0
45 stars 10 forks source link

CherryPy library is missing the definition of `is_closable_iterator` in 1.2.0 #19

Closed usox closed 8 years ago

usox commented 8 years ago

It looks like the shipped cherrypy library is missing at least the is_closeable_iterator definition.

Error:

Starting tvstreamrecord v.1.2.0 with Python 3.4
Logging output initialized
Initializing database... 
Initializing config...
Port changes saved, new port: 80, please restart the software
Checking internationalization...
Initializing records...
Record: Thread timer for 'Kalkofes Mattscheibe Rekalked - Mediensatire von und mit Oliver Kalkofe' started for 29239 seconds
Initializing EPG import thread...
EPG Thread timer waiting till 05:50 (57559 seconds)
Starting server on: 10.30.0.4:80
Traceback (most recent call last):
  File "tvstreamrecord.py", line 1163, in <module>
    run(host=config.cfg_server_bind_address, port=config.cfg_server_port, server=CherryPyServer, quiet=True)
  File "/opt/tvstreamrecord/bottle.py", line 3026, in run
    server.run(app)
  File "/opt/tvstreamrecord/bottle.py", line 2666, in run
    from cherrypy import wsgiserver
  File "/opt/tvstreamrecord/cherrypy/__init__.py", line 76, in <module>
    from cherrypy import _cptree
  File "/opt/tvstreamrecord/cherrypy/_cptree.py", line 7, in <module>
    from cherrypy import _cpconfig, _cplogging, _cprequest, _cpwsgi, tools
  File "/opt/tvstreamrecord/cherrypy/_cpwsgi.py", line 16, in <module>
    from cherrypy.lib import is_closable_iterator
ImportError: cannot import name 'is_closable_iterator'

Missing code in the shipped __init.py__ (diffed against cherrypy 3.8.1)

def is_iterator(obj):
    '''Returns a boolean indicating if the object provided implements
     the iterator protocol (i.e. like a generator). This will return
     false for objects which iterable, but not iterators themselves.'''
    from types import GeneratorType
    if isinstance(obj, GeneratorType):
        return True
    elif not hasattr(obj, '__iter__'):
        return False
    else:
        # Types which implement the protocol must return themselves when
        # invoking 'iter' upon them.
        return iter(obj) is obj

def is_closable_iterator(obj):

    # Not an iterator.
    if not is_iterator(obj):
        return False

    # A generator - the easiest thing to deal with.
    import inspect
    if inspect.isgenerator(obj):
        return True

    # A custom iterator. Look for a close method...
    if not (hasattr(obj, 'close') and callable(obj.close)):
        return False

    #  ... which doesn't require any arguments.
    try:
        inspect.getcallargs(obj.close)
    except TypeError:
        return False
    else:
        return True
Pavion commented 8 years ago

Hi, with a standard configuration I'm encountering no issues with supplied CherryPy, both Python 2.x and 3.x don't throw any exceptions. Do you have further steps to reproduce your problem? I've got but one idea:

As I see, you've tried to use port 80 for my application, which may have caused this problem. On my test systems everything is fine as long as I'm using port 8030 but switching to 80 throws an exception:

Both exceptions are legit, as both systems reserve their port 80 for other services.

P.S. Sadly, an exception on start won't let you change your port back. To get over this, you must delete the file "settings.db" in the application folder. This will also delete channels and recordings! If you want to keep your data, you can connect to this file using SQLite driver and change it manually or send me your file via E-Mail.

usox commented 8 years ago

The issue is not related to the port configuration. For testing purposes, I created a fresh linux VM (ubuntu 14.04), downloaded the 1.2.0 package and ran it using python2.7 - same result.

The import of the is_closeable_iterator in cherrypy/_cpwsgi.py:16 fails because of the missing definition (see https://github.com/cherrypy/cherrypy/blob/master/cherrypy/lib/__init__.py vs https://github.com/Pavion/tvstreamrecord/blob/master/cherrypy/lib/__init__.py)

Starting tvstreamrecord v.1.2.0 with Python 2.7
Logging output initialized
Initializing database... 
New database created. Thank you for using this package.
Initializing config...
Checking internationalization...
Initializing records...
Initializing EPG import thread...
Starting server on: 0.0.0.0:8030
Traceback (most recent call last):
  File "tvstreamrecord.py", line 1163, in <module>
    run(host=config.cfg_server_bind_address, port=config.cfg_server_port, server=CherryPyServer, quiet=True)
  File "/home/wolverine/aggi/tvstreamrecord-1.2.0/bottle.py", line 3026, in run
    server.run(app)
  File "/home/wolverine/aggi/tvstreamrecord-1.2.0/bottle.py", line 2666, in run
    from cherrypy import wsgiserver
  File "/home/wolverine/aggi/tvstreamrecord-1.2.0/cherrypy/__init__.py", line 76, in <module>
    from cherrypy import _cptree
  File "/home/wolverine/aggi/tvstreamrecord-1.2.0/cherrypy/_cptree.py", line 7, in <module>
    from cherrypy import _cpconfig, _cplogging, _cprequest, _cpwsgi, tools
  File "/home/wolverine/aggi/tvstreamrecord-1.2.0/cherrypy/_cpwsgi.py", line 16, in <module>
    from cherrypy.lib import is_closable_iterator
ImportError: cannot import name is_closable_iterator
Pavion commented 8 years ago

I've implemented a fix for dead servers (855ab0331a4ebde3043c482e5eff2b2dc26bf16c). Getting an exception on server start should now load a default server 0.0.0.0:8030 instead.

Pavion commented 8 years ago

Sorry, it seems, my 'lib' folder was excluded from all commits (52f6dc553fae153c7e048c3b5055d072cfd062d6). Thanks for waking me up! Please test and close this issue, if successful.

usox commented 8 years ago

Seems to work as expected ;)