Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autoreload: Conflicts with jetbrains debugger #2243

Closed
akoidan opened this issue Jan 6, 2018 · 11 comments
Closed

autoreload: Conflicts with jetbrains debugger #2243

akoidan opened this issue Jan 6, 2018 · 11 comments

Comments

@akoidan
Copy link

akoidan commented Jan 6, 2018

To reproduce the issue you can use default example:

import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hellof, world!")

def make_app():
    return tornado.web.Application([
        (r"/", MainHandler),
    ], debug=True, autoreload=True)

if __name__ == "__main__":
    app = make_app()
    app.listen(8888)
    tornado.ioloop.IOLoop.current().start()

Pycharm starts the script with
/usr/bin/python3.6 /opt/pycharm-eap/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 33261 --file file_name.py
If I edit the file and then save it I receive

Failed to import the site module
Traceback (most recent call last):
  File "/usr/lib/python3.6/site.py", line 73, in <module>
    import os
  File "/usr/lib/python3.6/os.py", line 652, in <module>
    from _collections_abc import MutableMapping
  File "/usr/lib/python3.6/_collections_abc.py", line 288, in <module>
    Iterator.register(str_iterator)
  File "/usr/lib/python3.6/abc.py", line 158, in register
    if issubclass(subclass, cls):
  File "/usr/lib/python3.6/abc.py", line 207, in __subclasscheck__
    ok = cls.__subclasshook__(subclass)
KeyboardInterrupt

This issue reproduces with python 3.6. On python 2.7 autoreload works ok. I also tried to turn off Safe write in pycharm, but that doesn't affect it at all.

@akoidan akoidan changed the title 'autoreload=true' throws 'KeyboardInterrupt' while in Pycharm debug 'autoreload=true' throws 'KeyboardInterrupt' while debugging with python3.6 Jan 6, 2018
@bdarnell
Copy link
Member

bdarnell commented Jan 6, 2018

It looks like pycharm is trying to do its own automatic reloading when you save the file by sending an interrupt signal to the original process. You don't need two kinds of reloading, so you probably want to turn off one or the other.

@akoidan
Copy link
Author

akoidan commented Jun 3, 2018

Probably related. https://youtrack.jetbrains.com/issue/PY-28604
Notes:

  • autoreload=false doesn't reload the code while in debug
  • If pycharm performs run instead of debug it doesn't run the script via pydevd.py so autoreload works fines.
  • I didn't find a way to turn off sending interrupting signal in pycharm, I guess it's hardcoded in pydevd.py

So atm it's impossible to have autoreloaded code while in debug in pycharm.

@bdarnell
Copy link
Member

bdarnell commented Jun 3, 2018

Ah, this is just while the debugger is attached? I wouldn't expect that to work at all - reloading the process will at least break the connection to the debugger. If the debugger has a reloading feature then you may be able to use that, but I think you'll need to turn off tornado's autoreload feature to debug. I don't think there's anything we can do about this on the tornado side; it's a question for jetbrains.

@akoidan
Copy link
Author

akoidan commented Jun 4, 2018

Well, it works somehow with python2, I guess there should be a chance get it working with py3

@andrey-yantsen
Copy link

@Deathangel908 actually it was working for python < 3.4 :( You can check https://youtrack.jetbrains.com/issue/PY-14980, there was a workaround

@desertkun
Copy link

@bdarnell The behavior has changed in 2018.3

It now does

[I 190219 15:17:05 autoreload:199] file.py modified; restarting server
Process finished with exit code 0

Regardless if you debug it or not

python -m ***.server --debug=true
...
[I 190219 15:19:53 autoreload:199] file.py modified; restarting server
Process finished with exit code 0

Adding -m tornado.autoreload -m ***.server trick doesn't help either.

@maxisme
Copy link

maxisme commented Feb 21, 2019

I am having the above issue too!

@gshmu
Copy link

gshmu commented Jan 15, 2020

I'm using pycharm's Attaching to a process to debug, and run tornado server manual.

the attache still broken, but the serve still runing and reload.

@rdboyett
Copy link

rdboyett commented Mar 5, 2020

I am currently having the same problem running py3.7. I was running intellij 2019.1 and it wouldn't work when I upgraded my application to py3 so I updated intellij ultimate to 2019.3 and it still breaks with KeyboardInterrupt only while using the debugger.

Traceback (most recent call last): File "/Users/robert/Library/Application Support/IntelliJIdea2019.3/python/helpers/pydev/pydevd.py", line 7, in <module> from contextlib import contextmanager File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 724, in exec_module File "<frozen importlib._bootstrap_external>", line 818, in get_code File "<frozen importlib._bootstrap_external>", line 916, in get_data KeyboardInterrupt

@prshir
Copy link

prshir commented Jun 28, 2023

Faced with the same issue in PyCharm 2021 and python 3.6. Regardless debug or not after any changes the server stops with Process finished with exit code 0
Autoreload works when I start the server from cmd

@bdarnell
Copy link
Member

bdarnell commented Jul 3, 2023

It is not expected that autoreload would work while a debugger is attached. If you use a debugger (I don't) you should turn off autoreload while debugging. If there's some way to detect the presence of a debugger and automatically disable autoreload while one is present, I would welcome the suggestion. Otherwise, I don't think there's anything for Tornado to do here and any questions should be directed to the debugger vendor (jetbrains, it seems, from every comment posted here).

@bdarnell bdarnell changed the title 'autoreload=true' throws 'KeyboardInterrupt' while debugging with python3.6 autoreload: Conflicts with jetbrains debugger Jul 3, 2023
@bdarnell bdarnell closed this as not planned Won't fix, can't repro, duplicate, stale Jul 3, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants