# the former to the latter, so subsequent executions won't have the same
# path as the original. Modify os.environ here to ensure that the
# re-executed process will have the same path.
- if sys.path[0] == '':
+ # Conversely, when run as path/to/tornado/autoreload.py, the directory
+ # containing autoreload.py gets added to the path, but we don't want
+ # tornado modules importable at top level, so remove it.
+ if (sys.path[0] == '' and
+ not os.environ.get("PYTHONPATH", "").startswith(".:")):
os.environ["PYTHONPATH"] = ".:" + os.environ.get("PYTHONPATH", "")
+ elif sys.path[0] == os.path.dirname(__file__):
+ del sys.path[0]
main()