Вопрос

I am confused as to why the bottlepy server doesn't run:

if __name__ == '__main__':
    start = datetime.now()
    db = Database(force_refresh_cache=False,
                  timestamp_filename='timestamp.pickle',
                  schema_filename='schema.pickle')
    print datetime.now(), 'Took:', (datetime.now() - start).total_seconds()

    run(host='localhost', port=80, reloader=True, debug=True)

When I comment out the db construction; the server runs.

In both cases I get the timestamped "Took: [seconds]" line, which implies that no error occurred earlier.

Это было полезно?

Решение

The problem is the module level code, and potentially the fact that you are using the reloader switch. Check this out.

All module level code is run at least twice when the reloader is on. I haven't tested this, but this would make sense as it wouldn't be able to spawn a child if the DB were already tied up.

try this:

if __name__ == '__main__':
    start = datetime.now()
    db = Database(force_refresh_cache=False,
                  timestamp_filename='timestamp.pickle',
                  schema_filename='schema.pickle')
    print datetime.now(), 'Took:', (datetime.now() - start).total_seconds()

    run(host='localhost', port=80, debug=True)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top