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

KeyboardInterrupt starts expensive background process #4

Closed
ulfaslak opened this issue Nov 12, 2018 · 28 comments
Closed

KeyboardInterrupt starts expensive background process #4

ulfaslak opened this issue Nov 12, 2018 · 28 comments
Labels
bug Something isn't working

Comments

@ulfaslak
Copy link
Collaborator

This is a weird one. When I KeyboardInterrupt in a Jupyter Notebook, a very CPU hungry Python process starts.

screen shot 2018-11-12 at 14 37 52

When I restart the kernel, it terminates. If I terminate it in the activity monitor, the Jupyter kernel becomes busy (no output in terminal).

Even weirder, if I launch a new visualization, IT STOPS.

benmaier added a commit that referenced this issue Nov 12, 2018
@benmaier
Copy link
Owner

possibly fixed (forgot thread.join()). Can you try?

@benmaier benmaier added the bug Something isn't working label Nov 12, 2018
@benmaier
Copy link
Owner

hey @ulfaslak did you have time to test it?

@ulfaslak
Copy link
Collaborator Author

Sorry, baby fog, will try later!

@benmaier
Copy link
Owner

benmaier commented Nov 19, 2018 via email

@ulfaslak
Copy link
Collaborator Author

Alright, it was fast enough to try. So I upgraded with pip to v0.0.6 (right one?), but the bug is still there.

@benmaier
Copy link
Owner

benmaier commented Nov 19, 2018 via email

@ulfaslak
Copy link
Collaborator Author

ah on sec

@ulfaslak
Copy link
Collaborator Author

ok i'm not being very thorough checking if I installed it right here, but downloading the repo and running python setup.py install it installs v 0.0.7, which also imports successfully, but throws the error DistutilsFileError: cannot copy tree '/anaconda3/lib/python3.7/site-packages/netwulf-0.0.7-py3.7.egg/netwulf/js': not a directory at visualize(G)

@benmaier
Copy link
Owner

benmaier commented Nov 19, 2018 via email

@ulfaslak
Copy link
Collaborator Author

Different behavior now. I interrupt and it doesn't stop, I interrupt it again and it throws error.
nov-19-2018 13-57-46

@benmaier
Copy link
Owner

benmaier commented Nov 19, 2018 via email

@benmaier
Copy link
Owner

is this fixed by now? 🤔

@benmaier
Copy link
Owner

can't reproduce

@ulfaslak
Copy link
Collaborator Author

ulfaslak commented Apr 9, 2019

This still happens to me. It's driving me crazy. Also, connected to this, the POST back to Python feature doesn't work. I'll look into this further and we can probably close this for now but jeeeeeesus....

@ulfaslak ulfaslak closed this as completed Apr 9, 2019
@benmaier
Copy link
Owner

benmaier commented Apr 9, 2019 via email

@ulfaslak
Copy link
Collaborator Author

ulfaslak commented Apr 9, 2019

It seems to everything right down to line 274 if interactive.py where it hangs on thread.join().

@benmaier
Copy link
Owner

benmaier commented Apr 9, 2019

I reopen this ... you won't be the only one having this problem

@benmaier benmaier reopened this Apr 9, 2019
@benmaier
Copy link
Owner

benmaier commented Apr 9, 2019 via email

@ulfaslak
Copy link
Collaborator Author

ulfaslak commented Apr 9, 2019

This is the output when hitting "Post to Python" and then upon returning to the notebook (where the kernel is still busy), interrupting the kernel:

changing directory to /Users/ulfaslak/.netwulf
starting server here ... /Users/ulfaslak/.netwulf
127.0.0.1 09/Apr/2019 14:17:27 GET /?data=tmp_16a02081db3.json&config=config_tmp_16a02081db3.json HTTP/1.1 200 -
127.0.0.1 09/Apr/2019 14:17:28 GET /config_tmp_16a02081db3.json HTTP/1.1 200 -
127.0.0.1 09/Apr/2019 14:17:28 GET /tmp_16a02081db3.json HTTP/1.1 200 -
127.0.0.1 09/Apr/2019 14:17:29 POST /?data=tmp_16a02081db3.json&config=config_tmp_16a02081db3.json HTTP/1.1 200 -
Successfully posted network data to Python!
127.0.0.1 09/Apr/2019 14:17:31 POST /?data=tmp_16a02081db3.json&config=config_tmp_16a02081db3.json HTTP/1.1 200 -
stopping server ...
was asked to stop the server
deleted all files
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-6-a227c1684ca5> in <module>
      6     v['group'] = v['block']; del v['block']
      7 
----> 8 visualize(G, verbose=True)

/anaconda3/lib/python3.7/site-packages/netwulf/interactive.py in visualize(network, port, verbose, config)
    272         print('stopping server ...')
    273     server.stop_this()
--> 274     thread.join()
    275 
    276     posted_network_properties = server.posted_network_properties

/anaconda3/lib/python3.7/threading.py in join(self, timeout)
   1030 
   1031         if timeout is None:
-> 1032             self._wait_for_tstate_lock()
   1033         else:
   1034             # the behavior of a negative timeout isn't documented, but

/anaconda3/lib/python3.7/threading.py in _wait_for_tstate_lock(self, block, timeout)
   1046         if lock is None:  # already determined that the C code is done
   1047             assert self._is_stopped
-> 1048         elif lock.acquire(block, timeout):
   1049             lock.release()
   1050             self._stop()

KeyboardInterrupt: 

@ulfaslak
Copy link
Collaborator Author

ulfaslak commented Apr 9, 2019

I'm on Python 3.7.3, and netwulf version 0.0.14

benmaier added a commit that referenced this issue Apr 9, 2019
@benmaier
Copy link
Owner

benmaier commented Apr 9, 2019

can you try with the latest commit? I'm pretty sure it won't work but a guy can dream

@ulfaslak
Copy link
Collaborator Author

ulfaslak commented Apr 9, 2019

I like your spirit but no cigar. Also, this never runs if you don't interrupt (click Post to Python in webapp)

@ulfaslak
Copy link
Collaborator Author

ulfaslak commented Apr 9, 2019

Can it have something to do with the http.serve_forever() line? And that it excepts OSErrors? I tried removing the try-except clause, and nothing happened, but still as I understand it, thread.join() is ineffective because thread is still busy.

Recall that everything runs smoothly down to and including line 273: server.stop_this()

@benmaier
Copy link
Owner

benmaier commented Apr 9, 2019 via email

@ulfaslak
Copy link
Collaborator Author

ulfaslak commented Apr 9, 2019

Cool thanks. No stress, just got hung up on this now...

@benmaier
Copy link
Owner

benmaier commented Apr 9, 2019

I've added a timeout to thread.join() -- can you try again with the new commit?

@benmaier
Copy link
Owner

benmaier commented Apr 9, 2019

I now added a functionality which stops serve_forever

@ulfaslak
Copy link
Collaborator Author

ulfaslak commented Apr 9, 2019

Sweet this works! Causes an error when doing a keyboardinterrupt in Jupyter, made a pull request that fixes this #13 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants