bcpy icon indicating copy to clipboard operation
bcpy copied to clipboard

`FileNotFoundError(2, 'No such file or directory')` when running job via cron

Open n3ddu8 opened this issue 1 year ago • 2 comments

I'm running the following code in my Python job on Ubuntu 22.04:

bdf = bcpy.DataFrame(df)
sql_table = bcpy.SqlTable(self.cnxns["sql_config"], table=f"{table_name}_temp")
bdf.to_sql(sql_table)

This works fine when called manually, however when it's scheduled to run via cron it raises the error FileNotFoundError(2, 'No such file or directory').

I suspect the issue is related to line 31 in the file tmp_file.py:

tmp_dir = os.environ['XDG_RUNTIME_DIR']

I wrote a small script to see what this returns:

import os
x = os.environ['XDG_RUNTIME_DIR']
print(type(x))
print(x)

When run manually, outputting to a text file, I get:

<class 'str'>
/run/user/1001

However when running via cron the file is blank.

n3ddu8 avatar Aug 03 '23 10:08 n3ddu8

Apologies, updating my small script to include:

import traceback
try:
    x = os.environ['XDG_RUNTIME_DIR']
except Exception as e:
    print(traceback.format_exc)

shows that it's actually raising a KeyError which the code allows for, so unsure why this isn't working. I've checked the directory /dev/shm however this does not contain any files related to my job.

n3ddu8 avatar Aug 03 '23 11:08 n3ddu8

One last comment on this, I've written a small script to write a DataFrame out using to_csv to /dev/shm/tmp.csv and run it both as a user and as cron and both were successful.

n3ddu8 avatar Aug 03 '23 11:08 n3ddu8