I'm working with TVM, a deep learning compiler. In my workflow, it is useful to be able to use import pdb; pdb.set_trace(), and drop into the debugger. However, pdb.set_trace() causes a segfault anytime after TVM has been imported.
My current setup is
- Ubuntu 16.04 (running on Windows Subsystem for Linux, but this happens on my native 16.04 machine too!)
- Python 3.6
This problem does not occur on Windows or Mac.
This problem only occurs when running a script from the commandline (i.e. python3 minimum-reproducible-example.py), not when running from the python3 repl.
I've done some debugging with gdb, and narrowed it down: the error occurs when the readline package is imported.
Minimum reproducible example:
import tvm
import readline
After debugging with gdb, I traced it to a specific line in cpython:
Program received signal SIGSEGV, Segmentation fault.
PyModule_GetState (m=0x0) at Objects/moduleobject.c:558
558 if (!PyModule_Check(m)) {
In this case, m is 0x0, which the function doesn't seem to expect.
If anyone could even just point me towards more useful ways to debug this, that would be helpful!
Related
I was using Raspberry Pi to perform some basic experiments and I wrote some Python scripts for that and they were fine. Then, for a new part of the analysis, I had to import SciPy. To be able to use SciPy, I had to install an older version. After that, I'm getting "ImportError" for every module. For example:
ImportError: cannot import name 'process' from partially initialized module 'multiprocessing' (most likely due to a circular import)"
Some people said it might be because of having the same script filename which will conflict with the multiprocessing module but this is not true in my case.
Also, I tried the analysis part of the code on different systems (Ubuntu on my laptop) and it works fine so I'm sure there is nothing wrong with the code.
I'm wondering if anyone else has ever had the same issue on Raspberry Pi?
Best regards,
Amir
module path lost in multiprocessing spawn (ModuleNotFoundError)
The so-called solution of inserting sys-path above the importing of the module does not work for me.
Here is my main.py
import multiprocessing
from testing import customfunction
customfunction(1,2,3)
if __name__ == "__main__":
process = multiprocessing.Process(target=customfunction)
process.start()
process.join()
print("DONE")
The main.py works fine up to process.start()
This means customfunction has been imported properly
Here is my testing.py
import random
def customfunction(size, test, hello):
random.seed(size)
print(random.random())
return random.random()
Both main.py and testing.py are in the same folder. A separate folder with an init.py file did not work as well.
I get this error:
from testing import customfunction
ModuleNotFoundError: No module named 'testing'
I can not wrap my head around why does the process created not retain the system pathing in order to import the file. If i place the multiprocessing creation in customfunction it doesn't work either, the same error occurs.
The link I shared at the top does not work for me as well.
Thank you for taking the time to read. If you believe this is a duplicate of another question, please link it and explain, I am new to python.
EDIT:
I am using Windows 10 as my OS
I have installed Spyder 4.1.4 using Anaconda Navigator, Python 3.7.7.
I installed using a executable package.
I have tested this code on VS Code as well.
I am running this via the two IDEs mentioned(E.G VS Code Powershell console and Spyder's Python Console by clicking run)
I generally currently believe it is an issue specific to my computer, and I'll like to know if its replicable in other Windows Systems and whether or not the linked "solution" in the first line works. With that I may be able to pinpoint my errors
This should work if you invoke multiprocessing.Process(target=customfunction, args=(1,2,3)) instead. I can't think of a reason why this would not work on Linux.
Can you update your question and provide the following information?
What OS are you using?
What version of Python are you running, and how was it installed?
How are you running main.py (e.g. from the command line, from an IDE, etc.)?
Any other details about your system configuration that might help others answer your question?
No multiprocessing print outputs (Spyder)
The solution mentioned here seems to solve my problem, I never expected either VS Code or Spyder's Console to have an issue with multiprocessing, but running the code in an external system terminal works.
Thank you to Melih Elibol for helping me think more clearly about the problem, I am new to python.
I've been utilizing jupyter notebooks for awhile and typically place an
import pdb;pdb.set_trace()
in my notebook, which works as expected. Recently, I removed all Python related packages from my Windows machine and installed Enthought Canopy 32-bit. Now when trying to step through code via pdb I get the following
> <ipython-input-6-fdf950c00f74>(1)<module>()->None
-> import pdb;pdb.set_trace()
(Pdb) n
> c:\users\<user>\appdata\local\enthought\canopy32\user\lib\site- packages\ipython\core\interactiveshell.py(2888)run_code()
-> sys.excepthook = old_excepthook
It seems to jump into interactiveshell.py and never gets back to the actual code I'm wanting to step through. I've noticed this also happens in the 64 bit distro of Enthought
I can't for the life of me figure out what is causing this very odd error.
I am running a script in python 2.7 in the spyder IDE for windows 7. It uses datetime.datetime.strptime at one point. I can run the code once and it seems fine (although I haven't finished debugging, so exceptions have been raised and it hasn't completed normally yet), then if I try running it again I get the following (end of traceback only is shown):
File "C:\path\to\test.py", line 220, in std_imp
self.data[key].append(dt.datetime.strptime(string_var, string_format_var))
ImportError: Failed to import _strptime because the import lockis held by another thread.
I am not running multiple threads with Threading etc. The only way to get the code to make it past this point is to completely restart the computer. Restarting spyder won't work. Web searches haven't seemed to yield any clues or indications of others who have had this happen.
Does anyone understand what is going on? Is this some sort of GIL problem? What is the import lock, and why does it seem to be preventing me from importing this method of the datetime module once I have already tried running the code once?
The solution, as noted by mfitzp, was to include a dummy call to datetime.datetime.strptime at the beginning of the script.
e.g.
# This is a throwaway variable to deal with a python bug
throwaway = datetime.datetime.strptime('20110101','%Y%m%d')
I'm working on a program that needs some threading. I wanted to get myself into this and tried several tutorials. Because of some special hardware I need to stick to Python 2.5.2 (r25:51908)
When I want to run the following code
import threading
class PrintThread(threading.Thread):
def run(self):
print "foobar"
thread = PrintThread()
thread.start()
I get the famous error "pythonw.exe has encountered a problem ...". This only happens on my PC. When I tried the very same code on a differenct PC with the same installation of Python (also with the same additional libraries like visa), it just works!
I uninstalled Python and reinstalled it again, but the error is still occuring. Any suggestions?