DEMorphy
DEMorphy copied to clipboard
Python Debugger hangs when importing DEMorphy
Hi,
I have a weird problem. If I import your library into my Django project the whole debugger hangs when trying to import your library.
When I just uncomment the import statement it is working again. Do you have any idea how to fix this? Unfortunately I can't share the code. It works when I am just executing the code!
The last lines of the stacktrace are the following:
Click to expand!
--- modulename: pydevd, funcname: notify_thread_created
pydevd.py(679): if self.writer is None:
pydevd.py(686): with self._lock_running_thread_ids if use_lock else NULL:
--- modulename: pydevd_constants, funcname: __enter__
pydevd_constants.py(388): return self
pydevd.py(687): if thread_id in self._running_thread_ids:
pydevd.py(688): return
--- modulename: pydevd_constants, funcname: __exit__
pydevd_constants.py(391): return self
pydevd.py(726): for t in all_threads:
pydevd.py(727): if getattr(t, 'is_pydev_daemon_thread', False):
pydevd.py(728): pass # I.e.: skip the DummyThreads created from pydev daemon threads
pydevd.py(726): for t in all_threads:
pydevd.py(727): if getattr(t, 'is_pydev_daemon_thread', False):
pydevd.py(728): pass # I.e.: skip the DummyThreads created from pydev daemon threads
pydevd.py(726): for t in all_threads:
pydevd.py(727): if getattr(t, 'is_pydev_daemon_thread', False):
pydevd.py(728): pass # I.e.: skip the DummyThreads created from pydev daemon threads
pydevd.py(726): for t in all_threads:
pydevd.py(757): thread_ids = list(self._running_thread_ids.keys())
pydevd.py(758): for thread_id in thread_ids:
pydevd.py(759): if thread_id not in program_threads_alive:
pydevd.py(758): for thread_id in thread_ids:
pydevd.py(762): for thread_id in program_threads_dead:
pydevd.py(766): if len(program_threads_alive) == 0:
pydevd.py(775): curr_thread_id = get_current_thread_id(threadingCurrentThread())
--- modulename: threading, funcname: current_thread
threading.py(1237): try:
threading.py(1238): return _active[get_ident()]
--- modulename: pydevd_constants, funcname: get_current_thread_id
pydevd_constants.py(339): try:
pydevd_constants.py(341): tid = thread.__pydevd_id__
pydevd_constants.py(342): if tid is None:
pydevd_constants.py(350): return tid
pydevd.py(777): for thread_id in (curr_thread_id, '*'):
pydevd.py(778): queue = self.get_internal_queue(thread_id)
--- modulename: pydevd, funcname: get_internal_queue
pydevd.py(599): if thread_id.startswith('__frame__'):
pydevd.py(601): return self._cmd_queue[thread_id]
pydevd.py(782): cmds_to_add_back = []
pydevd.py(784): try:
pydevd.py(785): while True:
pydevd.py(786): int_cmd = queue.get(False)
--- modulename: queue, funcname: get
queue.py(158): with self.not_empty:
--- modulename: threading, funcname: __enter__
threading.py(240): return self._lock.__enter__()
queue.py(159): if not block:
queue.py(160): if not self._qsize():
--- modulename: queue, funcname: _qsize
queue.py(203): return len(self.queue)
queue.py(161): raise Empty
--- modulename: threading, funcname: __exit__
threading.py(243): return self._lock.__exit__(*args)
pydevd.py(804): except _queue.Empty: # @UndefinedVariable
pydevd.py(806): for int_cmd in cmds_to_add_back:
pydevd.py(777): for thread_id in (curr_thread_id, '*'):
pydevd.py(778): queue = self.get_internal_queue(thread_id)
--- modulename: pydevd, funcname: get_internal_queue
pydevd.py(599): if thread_id.startswith('__frame__'):
pydevd.py(601): return self._cmd_queue[thread_id]
pydevd.py(782): cmds_to_add_back = []
pydevd.py(784): try:
pydevd.py(785): while True:
pydevd.py(786): int_cmd = queue.get(False)
--- modulename: queue, funcname: get
queue.py(158): with self.not_empty:
--- modulename: threading, funcname: __enter__
threading.py(240): return self._lock.__enter__()
queue.py(159): if not block:
queue.py(160): if not self._qsize():
--- modulename: queue, funcname: _qsize
queue.py(203): return len(self.queue)
queue.py(161): raise Empty
--- modulename: threading, funcname: __exit__
threading.py(243): return self._lock.__exit__(*args)
pydevd.py(804): except _queue.Empty: # @UndefinedVariable
pydevd.py(806): for int_cmd in cmds_to_add_back:
pydevd.py(777): for thread_id in (curr_thread_id, '*'):
--- modulename: pydevd, funcname: __exit__
pydevd.py(215): self.release()
--- modulename: pydevd, funcname: release
pydevd.py(208): self._lock.release()
pydevd.py(209): self._tls.is_lock_acquired = False
pydevd.py(141): self._py_db_command_thread_event.clear()
--- modulename: threading, funcname: clear
threading.py(530): with self._cond:
--- modulename: threading, funcname: __enter__
threading.py(240): return self._lock.__enter__()
threading.py(531): self._flag = False
--- modulename: threading, funcname: __exit__
threading.py(243): return self._lock.__exit__(*args)
pydevd.py(142): self._py_db_command_thread_event.wait(0.3)
--- modulename: threading, funcname: wait
threading.py(548): with self._cond:
--- modulename: threading, funcname: __enter__
threading.py(240): return self._lock.__enter__()
threading.py(549): signaled = self._flag
threading.py(550): if not signaled:
threading.py(551): signaled = self._cond.wait(timeout)
--- modulename: threading, funcname: wait
threading.py(286): if not self._is_owned():
--- modulename: threading, funcname: _is_owned
threading.py(257): if self._lock.acquire(0):
threading.py(261): return True
threading.py(288): waiter = _allocate_lock()
threading.py(289): waiter.acquire()
threading.py(290): self._waiters.append(waiter)
threading.py(291): saved_state = self._release_save()
--- modulename: threading, funcname: _release_save
threading.py(249): self._lock.release() # No state to save
threading.py(292): gotit = False
threading.py(293): try: # restore state no matter what (e.g., KeyboardInterrupt)
threading.py(294): if timeout is None:
threading.py(298): if timeout > 0:
threading.py(299): gotit = waiter.acquire(True, timeout)
I made thread safety, it should not be a problem in multithreaded/multiprocessing environment to use the lib in general.
Can you please try the library in your local first?
Hi, I tried it locally but it is not working.
I created a fork: https://github.com/AlessandroVol23/DEMorphy/tree/issue/debug_issue
I can execute the file test.py without problems but when I try to debug the line after importing the library it hangs indefinitely.
I already tried it with some adjustments I think the problem is the large imports in some of the files, e.g. in demorphy/data/__init__.py the line from demorphy.data.lemmas import lemmas hangs very long. If I save the lemmas as a .txt file and load them it is working in some cases, but in some cases I still have to wait > 10 mins till the debugger responds.
Are you able to debug (with e.g. PyCharm or VSCode)?
Do you have any idea how to resolve this issue?
Thanks!
Yes of course, I'll debug in VSCode
I already tried it with some adjustments I think the problem is the large imports in some of the files
That might be the case, I can create a dumb project in Django and try.
Okay because I tried it with other clean environments, different OS (Ubuntu, Windows) and even on another PC but unfortunately I don't get it running in PyCharm and VSCode.
That would be great if you could create a dumb project in Django, thanks! :-)
So, after moving lemmas and paradigms to external .txt files it seems to work :-)
Ok my bad, after removing all import statements and using the .txt files for importing I can't debug again. So if you would have an example where it is working it would be great :+1: