0

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.

A T
  • 13,008
  • 21
  • 97
  • 158

1 Answers1

1

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)
Community
  • 1
  • 1
Tadgh
  • 1,999
  • 10
  • 23
  • Thanks for that, now tempted to write a function to ensure the database is always constructed for each of the endpoints… unfortunately I would need to decorate every endpoint with this. Is there an alternative, if I want: `reloader=True`? – A T May 19 '13 at 17:57
  • I find the functionality of the reloader to be pretty buggy anyhow. You could add a persistent file that indicates whether or not the DB has been loaded, to ensure only one instance is loaded, but I can't think of anything else off the top of my head. – Tadgh May 19 '13 at 19:09