Skip to content

autoreload: Conflicts with jetbrains debuggerΒ #2243

Closed as not planned
Closed as not planned

Description

@akoidan

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.

Activity

  1. changed the title [-]'autoreload=true' throws 'KeyboardInterrupt' while in Pycharm debug[/-] [+]'autoreload=true' throws 'KeyboardInterrupt' while debugging with python3.6[/+] on Jan 6, 2018
  2. bdarnell commented on Jan 6, 2018

    @bdarnell
    Member

    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.

  3. akoidan commented on Jun 3, 2018

    @akoidan
    Author

    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.

  4. bdarnell commented on Jun 3, 2018

    @bdarnell
    Member

    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.

  5. akoidan commented on Jun 4, 2018

    @akoidan
    Author

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

  6. worried-networking commented on Jun 15, 2018

    @worried-networking

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

  7. desertkun commented on Feb 19, 2019

    @desertkun

    @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.

  8. maxisme commented on Feb 21, 2019

    @maxisme

    I am having the above issue too!

  9. gshmu commented on Jan 15, 2020

    @gshmu

    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.

  10. rdboyett commented on Mar 5, 2020

    @rdboyett

    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

  11. prshir commented on Jun 28, 2023

    @prshir

    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

  12. bdarnell commented on Jul 3, 2023

    @bdarnell
    Member

    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).

  13. changed the title [-]'autoreload=true' throws 'KeyboardInterrupt' while debugging with python3.6[/-] [+]autoreload: Conflicts with jetbrains debugger[/+] on Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions