Airflow task fails with segmentation fault - python

I'm trying to execute this jar file https://github.com/RMLio/rmlmapper-java from Airflow, but for some reason it is failing straight away. I'm using a PythonOperator to execute some python code, and inside it I have a subprocess call to the java command.
Test command is:
java -jar /root/airflow/dags/rmlmapper-6.0.0-r363-all.jar -v
I'm running Airflow inside a Docker container. The weird thing is that if I execute the exact same command inside the container it works fine.
I tried a bit of everything but the result is always the same: SegFault 139
The memory of the container seems to be fine so it shouldn't be directly related to some OOM issue. I also tried to reset default memory in the Docker compose file with no success.
My suggestion is that the java application somehow tries to load some files which are stored locally inside the jar file, but for some reason maybe Airflow changes the 'user.dir' directory and therefore it is not able to find them and it fails.
I'm really out of ideas so any help will be highly appreciated. Thank you.

Related

Debugging any Known Python File Ran by an Interpreter

I'm trying to debug any Python script that an interpreter runs so long and I have a reference to that script. I.e if my connected interpreter runs a script called abc.py, and in my script directory I have abc.py with breakpoints attached. The IDE will automatically stop execution at that break point
I'm using PyCharm, but I'd like to know the theory here to say if I'd ever like to connect VS Code I'd be able to do that as well. Additionally I'm currently connecting to a Docker container running airflow.
Given the above, I'm assuming that the goal is to do a "remote" debug.
Also since Python is a script, and run by an interpreter I am assuming, if I can read into the interpreter and if PyCharm can match the file ran by the interpreter then it should be able to pause the execution.
I am additionally assuming that the interpreter can run in "normal" mode. Not in debug mode as we have in Java.
I have read three approaches:
ssh interpreter to my Docker container - seems most promising for my current goal, but unsure if it'll work
using Python debug server (Debugging Airflow Tasks with IDE tools?) - still requires manual changes in the specific scripts
using Docker interpreter (https://medium.com/#andrewhharmon/apache-airflow-using-pycharm-and-docker-for-remote-debugging-b2d1edf83d9d) - still requires individual debug configs for executing a single DAG / script
Is debugging any file executed by a python interpreter possible, at least in theory?
Is it possible remotely?
Is it possible using airflow at all?

Where are files created in a docker container stored?

I have a python script in one of my docker containers. I'm trying to log errors that occur during execution of the script:
with open('logs.txt', 'a+') as filehandle:
filehandle.write('Error message here')
Locally, logs.txt is created when I run : python path/to/script.py. However, when I run the script from docker like so; docker-compose exec service_name python path/to/script.py, I can't locate the logs file.
I have gone through a lot of documentation about bound mounts, volumes and other stuff. However, none of these are helping.
I need help with locating the logs.txt file. It'd also be great to get info about the 'right way' of storing such data.
Edit: Here's what I've tried so far
I already tried to explore the contents of my container via: docker exec -it container_name /bin/sh. I still couldn't find logs.txt.
PS: I'm new to docker, so please forgive my ignorance.

How do I move a container from one docker to another?

I know similar questions have been asked but I couldn't get it working or it was not specific enough for me since I am fairly new to dockers. The question is similar to the question in this thread How to move Docker containers between different hosts? but I don't fully understand the answer or I can't get it working.
My problem: I am using docker Desktop to run a python script locally in a container. But I want this python script to be able to run on a windows server 2016. The script is a short webscraper which creates a csv file.
I am aware I need to install some sort of docker on the webserver and I need to export my container and be able to load in the container at the webserver.
In the thread referred above it says that I need to use docker commit psscrape but when I try to use it.
I get: "Error response from daemon: No such container: psscraper." This is probably since the container has ran but stopped. Since the program runs only for a few seconds. psscraper is in the 'docker ps -a' list but not in the 'docker ps' list. I guess it has something to do with that.
psscraper is the name of the python file.
Is there anyone who could enlighten me on how to proceed?

How to debug hanging python code when I can't use PDB

I have some code that I'm able to run perfectly fine on my local system. Only when I launch it to run automatically as a docker containerized program on a server, does it hang and time out at a particular line. I'm not able to step through the program with pdb in that particular environment, nor can I reproduce the behavior in an environment where I could use a debugger. I can just see in my cloudwatch logs that it's stopping on that line and timing out.
That line of code that is hanging is calling other code, but I don't know internally the exact point where it hangs. Is there any way to wrap something around this line of code that will make it print out every step that it goes through?
(For reference, the actual server is an AWS SageMaker endpoint which is not directly accessible via ssh or anything, and the line of code that is timing out is an AutoGluon model.predict() call.)
I guess what I'm looking for could potentially be something like a debug decorator, or a way to automate pdb and wrap it around a function call to see where it's hanging. Or any better suggestions.
Perhaps you could do a sagemaker local session combined with remote pdb. https://pypi.org/project/remote-pdb/ You need the local session so you can easily get inside the container and remote-pdb lets you then connect.

Localhost has stopped updating when various flask/python scripts are run, how do I fix this?

I've been testing out a few .py files with Flask, referring to 127.0.0.1:5000 frequently to see if they're interfacing correctly with the HTML, after running the .py I'm getting the following as normal:
* Running on http://127.0.0.1:5000/
* Restarting with reloader
However, 127.0.0.1:5000 has suddenly stopped updating when scripts are run, remaining as it was after the first time a script was run since my computer has been turned on (restarting the machine is the only way I've found to take a fresh look at my work). To confirm that it's not an issue within .py files or my templates, Flask's hello world example with app.run(debug=True) does not update this localhost page when run. Is there any way to remedy this?
Two things that may or may not be involved with this issue:
(1) I am not using virtualenv but simply running .py files from folder directories on my desktop (following proper format for Flask and the template engine, though). (2) Around the time the problem started I installed SQLAlchemy and its Flash extension, Flask-SQLAlchemy with pip.
After tracking the processes down by running $ netstat -a -o in the command line, it turns out it wasn't a code error, but rather multiple instances of pythonw.exe, which can be taken care of in the Task Manager. I'm not sure why the processes keep running after I close out of all python windows, or why it keeps communicating with 127.0.0.1:5000, however, so thoughts on this would still be appreciated.
Thats right. Just press 'Ctrl+Shift+Esc' to open the task manager.
Scroll down to find the 'python3.exe' files and end the task manually.
The reason is 'ctrl+c' doesnt work for me (it just copies the text on terminal window), so I have to manually kill the python interpreter running in the background. Its hard work, but hey atleast you dont have to restart your computer everytime!!

Categories

Resources