Jupyter Notebook runs code unresponsively
In the process of learning face recognition knowledge need to use Anaconda, Jupyter Notebook.
I'm running unresponsive new code after starting Jupyter Notebook.
I couldn't observe what the problem was from the page, but then I started Jupyter Notebook in Anaconda Pormpt, which I thought was auto-starting at first, and foolishly waited for it to run automatically.
The result is that the operation is done in the browser, and it's the command line that runs the module.
To execute the code snippet in the browser shift+enter wraps this error in the background.
(tensorflow) C:\Users\admin>jupyter notebook
[I 15:55:33.979 NotebookApp] The port 8888 is already in use, trying another port.
[I 15:55:34.011 NotebookApp] The port 8889 is already in use, trying another port.
[I 15:55:34.130 NotebookApp] Serving notebooks from local directory: C:\Users\admin
[I 15:55:34.131 NotebookApp] The Jupyter Notebook is running at:
[I 15:55:34.137 NotebookApp] http://localhost:8890/?token=7d8aff641154f969e61dec8ebd511d98849f08829e440fe0
[I 15:55:34.139 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 15:55:34.220 NotebookApp]
To access the notebook, open this file in a browser:
file:///C:/Users/admin/AppData/Roaming/jupyter/runtime/
Or copy and paste one of these URLs:
http://localhost:8890/?token=7d8aff641154f969e61dec8ebd511d98849f08829e440fe0
Traceback (most recent call last):
File "C:\Users\admin\Anaconda3\envs\tensorflow\lib\site-packages\tornado\", line 888, in start
handler_func(fd_obj, events)
File "C:\Users\admin\Anaconda3\envs\tensorflow\lib\site-packages\tornado\stack_context.py", line 277, in null_wrapper
return fn(*args, **kwargs)
File "C:\Users\admin\Anaconda3\envs\tensorflow\lib\site-packages\zmq\eventloop\", line 450, in _handle_events
self._handle_recv()
File "C:\Users\admin\Anaconda3\envs\tensorflow\lib\site-packages\zmq\eventloop\", line 480, in _handle_recv
self._run_callback(callback, msg)
File "C:\Users\admin\Anaconda3\envs\tensorflow\lib\site-packages\zmq\eventloop\", line 432, in _run_callback
callback(*args, **kwargs)
File "C:\Users\admin\Anaconda3\envs\tensorflow\lib\site-packages\tornado\stack_context.py", line 277, in null_wrapper
return fn(*args, **kwargs)
File "C:\Users\admin\Anaconda3\envs\tensorflow\lib\site-packages\ipykernel\", line 283, in dispatcher
return self.dispatch_shell(stream, msg)
File "C:\Users\admin\Anaconda3\envs\tensorflow\lib\site-packages\ipykernel\", line 233, in dispatch_shell
self.pre_handler_hook()
File "C:\Users\admin\Anaconda3\envs\tensorflow\lib\site-packages\ipykernel\", line 248, in pre_handler_hook
self.saved_sigint_handler = signal(SIGINT, default_int_handler)
File "C:\Users\admin\Anaconda3\envs\tensorflow\lib\", line 47, in signal
handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread
[IPKernelApp] WARNING | Parent appears to have exited, shutting down.
then refer tohttps:///article/ Solution.
(tensorflow) C:\Users\admin>pip install "pyzmq==17.0.0" "ipykernel==4.8.2"
Collecting pyzmq==17.0.0
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='', port=443): Read timed out. (read timeout=15)",)': /simple/pyzmq/
Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='', port=443): Read timed out. (read timeout=15)",)': /simple/pyzmq/
Downloading /packages/27/0b/a275f30738a014dc25443d2f45156ca739991df581fdaa40aa19df6c4f86/pyzmq-17.0.0-cp36-cp36m-win_amd64.whl (944kB)
100% |████████████████████████████████| 952kB 49kB/s
Collecting ipykernel==4.8.2
Downloading /packages/ab/3f/cd624c835aa3336a9110d0a99e15070f343b881b7d651ab1375ef226a3ac/ipykernel-4.8. (108kB)
100% |████████████████████████████████| 112kB 58kB/s
Requirement already satisfied: ipython>=4.0.0 in c:\users\admin\anaconda3\envs\tensorflow\lib\site-packages (from ipykernel==4.8.2) (6.1.0)
Requirement already satisfied: tornado>=4.0 in c:\users\admin\anaconda3\envs\tensorflow\lib\site-packages (from ipykernel==4.8.2) (4.5.2)
Requirement already satisfied: traitlets>=4.1.0 in c:\users\admin\anaconda3\envs\tensorflow\lib\site-packages (from ipykernel==4.8.2) (4.3.2)
Requirement already satisfied: jupyter-client in c:\users\admin\anaconda3\envs\tensorflow\lib\site-packages (from ipykernel==4.8.2) (5.2.4)
Requirement already satisfied: jupyter-core in c:\users\admin\anaconda3\envs\tensorflow\lib\site-packages (from jupyter-client->ipykernel==4.8.2) (4.4.0)
Requirement already satisfied: python-dateutil>=2.1 in c:\users\admin\anaconda3\envs\tensorflow\lib\site-packages (from jupyter-client->ipykernel==4.8.2) (2.6.1)
Requirement already satisfied: six>=1.5 in c:\users\admin\anaconda3\envs\tensorflow\lib\site-packages (from python-dateutil>=2.1->jupyter-client->ipykernel==4.8.2) (1.10.0)
Installing collected packages: pyzmq, ipykernel
Found existing installation: pyzmq 17.1.2
Uninstalling pyzmq-17.1.2:
Successfully uninstalled pyzmq-17.1.2
Found existing installation: ipykernel 4.6.1
Cannot uninstall 'ipykernel'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
I got an error when installing, ipykernel can't be uninstalled, and I've tried reinstalling it, and it keeps reporting this error. So I just left it alone and just re-ran it in my browser and it worked fine.
Here's how it runs after the fix.
jupyter notebook A cell keeps running.
Recently debugging program, found a simple code has been running for a long time without termination, the code is as follows:
whole_df=pd.read_csv(r'./') community=whole_df['COMMUNITY_ID'].unique() for community_id in community: temp=check_result[check_result['COMMUNITY_ID']==community_id] start=()[0] delanomaly_test(temp,start)
Among them, delanomaly_test is a function that handles outliers on the test data, and the function has the operation of assigning a value to the formal parameter temp, which is a slice of whole_df, and after executing it, a lot of prompts appeared:
/usr/local/python3/lib/python3.6/site-packages/pandas/core/:1763: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: /pandas-docs/stable/user_guide/#returning-a-view-versus-a-copy
A large series of all the prompts, and has been expanding down, after 10 minutes, no longer appear prompts, but this cell execution symbols show '*', has been in the execution of the amount of data itself is not large, community for 200, check_result for 80,000, it should be 2, 3 minutes! It should end in 2 or 3 minutes, but after another 5 minutes, it still has the '*' sign, and the point 'Interrupt the kernel' is also not responding for a long time. I tested it by writing standard output and writing a file:
whole_df=pd.read_csv(r'./') community=whole_df['COMMUNITY_ID'].unique() filename='' with open(file_name,'w+') as f: (file_name) w=0 # Variables for progress for community_id in community: if w%50==0: print('w=%s' %str(w)) # Print to standard output f=open(file_name,'a') ('\n '+str(w)+':')# Write to file (('%Y-%m-%d %H:%M:%S',(()))) () temp=check_result[check_result['COMMUNITY_ID']==community_id] start=()[0] delanomaly_test(temp,start) w=w+1 print('w=%s' %str(w)) # Print to standard output f=open(file_name,'a') print('w=%s' %str(w)) ('\n '+str(w)+':') # Write to file (('%Y-%m-%d %H:%M:%S',(()))) ('\n check_result executed ') ()
After execution, the contents of the file are as follows:
0:2021-08-25 21:14:38
50:2021-08-25 21:14:43
100:2021-08-25 21:14:49
150:2021-08-25 21:14:54
200:2021-08-25 21:15:00
check_result executed
It seems that this code has been executed in less than a minute, and looking at the standard output again, there are still a lot of previous prompts, while only three are found in the w-value labeling progress:
w=0
w=50
w=100
Further back there are only hints, and further back the hints are terminated
Therefore, the possible reason why this code keeps executing is that a large amount of content is written to the standard output in a short period of time, and the buffer of the standard output is full, so it cannot print the prompts and the content after that, but the program has actually finished executing. Finally, remove the slice assignment statement in the delanomaly_test function, and find that this code ends very quickly, so there are three problems: slices can not be assigned directly, the standard output is not reliable, and each prompt should be carefully read!
summarize
The above is a personal experience, I hope it can give you a reference, and I hope you can support me more.