kochat in use RuntimeError: main thread is not in main loop - python

kochat is a Korean chatbot, and I ran into a problem while practicing it.
github imformation : https://github.com/hyunwoongko/kochat
It is environment setting
python3.8
pip install kochat
JPype is reinstalled ues JPype1-1.2.0-cp38-cp38-win_amd64.whl <-download
pytorch is same ver with cuda 11.1
start code
### from kochat.proc import DistanceClassifier ###
from kochat.data import Dataset
from kochat.proc import GensimEmbedder, DistanceClassifier
from kochat.model import intent, embed
from kochat.loss import CenterLoss
dataset = Dataset(ood=True)
emb = GensimEmbedder(model=embed.Word2Vec())
# 프로세서 생성
clf = DistanceClassifier(
model=intent.CNN(dataset.intent_dict),
loss=CenterLoss(dataset.intent_dict)
)
# 되도록이면 DistanceClassifier는 Margin 기반의 Loss 함수를 이용해주세요
# 현재는 CenterLoss, COCOLoss, Cosface, GausianMixture 등의
# 거리기반 Metric Learning 전용 Loss함수를 지원합니다.
# 모델 학습
clf.fit(dataset.load_intent(emb))
# 모델 추론 (인텐트 분류)
clf.predict(dataset.load_predict("오늘 서울 날씨 어떨까", emb))
error message
C:\projectkyc\kochat3.8\Scripts\python.exe "C:/projectkyc/kochat3.8/test3.8/!from kochat.proc import DistanceClassifier.py"`enter code here`
Exception ignored in: <function Image.__del__ at 0x000001E7E1566D30>
Traceback (most recent call last):
File "c:\users\user\appdata\local\programs\python\python38\lib\tkinter\__init__.py", line 4014, in __del__
Exception ignored in: <function Variable.__del__ at 0x000001E7E154B430>
Traceback (most recent call last):
File "c:\users\user\appdata\local\programs\python\python38\lib\tkinter\__init__.py", line 351, in __del__
if self._tk.getboolean(self._tk.call("info", "exists", self._name)):
RuntimeError: main thread is not in main loop
Exception ignored in: <function Image.__del__ at 0x000001E7E1566D30>
Traceback (most recent call last):
File "c:\users\user\appdata\local\programs\python\python38\lib\tkinter\__init__.py", line 4014, in __del__
self.tk.call('image', 'delete', self.name)
RuntimeError: main thread is not in main loop
#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (os_windows_x86.cpp:144), pid=11208, tid=0x00000000000037f4
# guarantee(result == EXCEPTION_CONTINUE_EXECUTION) failed: Unexpected result from topLevelExceptionFilter
#
# JRE version: Java(TM) SE Runtime Environment (8.0_281-b09) (build 1.8.0_281-b09)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.281-b09 mixed mode windows-amd64 compressed oops)
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\projectkyc\kochat3.8\test3.8\hs_err_pid11208.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Exception ignored in: <function Image.__del__ at 0x000001E7E1566D30>
Traceback (most recent call last):
File "c:\users\user\appdata\local\programs\python\python38\lib\tkinter\__init__.py", line 4014, in __del__
self.tk.call('image', 'delete', self.name)
RuntimeError: main thread is not in main loop
Tcl_AsyncDelete: async handler deleted by the wrong thread
Process finished with exit code 1
If I haven't posted it or if I have the information I need, I will add it immediately upon confirmation if requested.

This is such an annoying issue and to me setting matplotlib.use('Agg') does not cut it. I dont want to comprise on this.
The only thing that seems to do it somewhat consistently is having to close the figure before creating a new plot via plt.close(). This is annoying and if i forget it does this.

this error
Matplotlib - Tcl_AsyncDelete: async handler deleted by the wrong thread?
same Question But did not know where to apply
The places to apply are kochat\utils\visualizer.py and kochat\proc\utils\visualizer.py
to be. In the
from matplotlib import pyplot as plt
part of these two places,
import matplotlib
matplotlib.use('Agg')
from matplotlib import pyplot as plt
The problem is solved.

Related

Python Error: Application file not generated?

I want to simulate a OpenModelica Model in Python with the help of OMPython. The following is my code:
import matplotlib.pyplot as plt
import OMPython
from OMPython import OMCSessionZMQ
from OMPython import ModelicaSystem
omc = OMCSessionZMQ()
mod = ModelicaSystem("Li_ionBattery.mo", "Li_ionBattery.TestBench.VaryingCurrent")
Li_simulation = mod.getSimulationOptions()
mod.setSimulationOptions(["stopTime=2000", "stepSize=50"])
variables_vary = mod.getQuantities()
Parameters_vary = mod.getParameters()
continous_vary = mod.getContinuous()
mod.setParameters(["nMC_Data.Q_nom=11", "nMC_Data.Rs=0.0003"])
mod.simulate()
And I am getting the following error:
Notification: Li_ionBattery requested package Modelica of version 3.2.2. Modelica 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
Error: Class Li_ionBattery.TestBench.VaryingCurrent not found in scope <top>.
Error: Class Li_ionBattery.TestBench.VaryingCurrent not found in scope <TOP>.
stopTime !is not a simulation-option variable
Traceback (most recent call last):
raise Exception("Error: application file not generated yet")
Exception: Error: application file not generated yet
The error is at line,
mod = ModelicaSystem("Li_ionBattery.mo", "Li_ionBattery.TestBench.VaryingCurrent")
as it reports,
Error: Class Li_ionBattery.TestBench.VaryingCurrent not found in scope <top>.
Make sure the class Li_ionBattery.TestBench.VaryingCurrent exists in Li_ionBattery.mo.

Creating a Dask client results in endless loop of errors

When I run this code:
from dask.distributed import Client
client = Client(n_workers = 2, threads_per_worker = 2, memory_limit = '2GB', silence_logs='error')
client
I get endless loop of these errors:
tornado.application - ERROR - Exception in callback <bound method Nanny.memory_monitor of <Nanny: None, threads: 2>>
Traceback (most recent call last):
File "C:\Users\szlau\anaconda3\lib\site-packages\tornado\ioloop.py", line 907, in _run
return self.callback()
File "C:\Users\szlau\anaconda3\lib\site-packages\distributed\nanny.py", line 414, in memory_monitor
process = self.process.process
Note: I have also tried reinstalling the whole Anaconda environment and the error still persists.
I really have no idea what can be causing this or how to eliminate this.
Any suggestions are welcomed!
At a guess, you are running your code in a script. That means that when dask creates the cluster and associated worker processes, those will, in turn, also runt he script and also attempt to create new clusters and processes.
You should guard your client and cluster creation with
if __name__ == "__main__":
client = Client(...)

Python - script made with gym does not work on Mac

I am following the tutorial here to learn Deep Reinforcement Learning (I am very new to the topic).
When I try to run the script below on my Macbook it returns me an Import Error (ImportError: sys.meta_path is None, Python is likely shutting down).
I tried to run it from the Mac terminal and also in Pycharm with the same result.
I tried also with other deep learning scripts and the error is the same (it seems not related to this script in particular).
Could you please help me understanding where I am wrong?
Script:
# Import the gym module
import gym
# Create a breakout environment
env = gym.make('BreakoutDeterministic-v4')
# Reset it, returns the starting frame
frame = env.reset()
# Render
env.render()
is_done = False
while not is_done:
# Perform a random action, returns the new frame, reward and whether the game is over
frame, reward, is_done, _ = env.step(env.action_space.sample())
# Render
env.render()
Error below:
/usr/local/bin/python3.6 /Users/marcogdepinto/PycharmProjects/PlayPong/pong.py
2018-05-12 18:58:11.915 Python[567:12594] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to (null)
Exception ignored in: <bound method SimpleImageViewer.__del__ of <gym.envs.classic_control.rendering.SimpleImageViewer object at 0x10b65bc88>>
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/gym/envs/classic_control/rendering.py", line 347, in __del__
File "/usr/local/lib/python3.6/site-packages/gym/envs/classic_control/rendering.py", line 343, in close
File "/usr/local/lib/python3.6/site-packages/pyglet/window/cocoa/__init__.py", line 281, in close
File "/usr/local/lib/python3.6/site-packages/pyglet/window/__init__.py", line 770, in close
ImportError: sys.meta_path is None, Python is likely shutting down
Process finished with exit code 0
"Try adding env.close() at the end of your programs, in my scenario,
it works nice"
src
Just add the lines below at the end of your program, the Error is raised during GC of the gym module.
try:
del env
except ImportError:
pass

'NoneType' object is not callable error when using couchbase with git, logbook module

I'd experienced weird result when testing couchbase python SDK.
below is the source code and result:
# xxx.py
from gcouchbase.bucket import Bucket
dsn = 'couchbase://[url-of-couchbase]/[bucket-name]'
db = Bucket(dsn)
# yyy.py
import logbook
import git
from xxx import db
# python yyy.py
Traceback (most recent call last):
File "/home/username/env/local/lib/python2.7/site-packages/gcouchbase/iops_gevent10.py", line 88, in timer_event_factory
return GEventTimer()
TypeError: 'NoneType' object is not callable
[1] 8546 abort (core dumped) python yyy.py
The weird thing is, when I remove import git or import logbook from yyy.py, the error doesn't happen.
Is there any reason for this error? should any resource for couchdb be disposed?
An asynchronous event seems to arrive after the Bucket object has been removed. If you call bucket._close() explicitly, the script would not be crashed. Anyways, it looks like a bug of gcouchbase.

Intercept Messages from 3rd Party Code

I am writing a Python script that uses 3rd party modules from GDAL. The GDAL functions do not raise exceptions when an error occurs, but do send messages to stdout. Generally, the errors that occur with GDAL functions do not warrant stopping the process and I don't need to know about the error having occurred.
Is there a way I can intercept the messages that are being sent to stdout before they are printed in the console? The GDAL messages interfere with the messages that I have provided in my own code.
As described in "Python Gotchas", you can turn on Exceptions using gdal.UseExceptions(), e.g.:
from osgeo import gdal
dsrc = gdal.Open('nonexist')
# ... silence
gdal.UseExceptions()
dsrc = gdal.Open('nonexist')
# Traceback (most recent call last):
# File "<interactive input>", line 1, in <module>
# RuntimeError: `nonexist' does not exist in the file system,
# and is not recognised as a supported dataset name.
You could always then use a try except block get the actual error message string:
try:
dsrc = gdal.Open('nonexist')
except RuntimeError as e:
print(str(e))
which will print the error message:
`nonexist' does not exist in the file system,
and is not recognised as a supported dataset name.

Categories