Refactored applicationinstance.py

- Use a property for pid. If ApplicationInstance.pid is accessed
  the pid file is to be read.
- Chose proper method names.
- Use context managers instead of file = open() hacks.