jupyter-server / jupyter-scheduler

Run Jupyter notebooks as jobs
https://jupyter-scheduler.readthedocs.io
BSD 3-Clause "New" or "Revised" License
196 stars 23 forks source link

Task Scheduler error: 'Cannot create a file when that file already exists' #379

Closed LAgeoNative closed 6 months ago

LAgeoNative commented 1 year ago

Description

Scheduling a task to execute now. However, after running for 2 seconds, it stops and produces an error that says 'Cannot create a file when that file already exists'

Reproduce

  1. This is my following code where it seems to produce the error message:

    currentYear = datetime.now().year def month_format(): currentMonth = datetime.now().month currentMonth = str(currentMonth) if len(currentMonth) < 2: currentMonth = "0" + currentMonth return currentMonth

    currentMonth = month_format() folder_date = str(currentYear) + str(currentMonth) path_date = './' + folder_date + '/' os.mkdir(path_date)

    image

Expected behavior

Scheduler creates the folder without giving me the error messages mentioned from the description image

Context

Troubleshoot Output
Paste the output from running `jupyter troubleshoot` from the command line here.
You may want to sanitize the paths in the output.
Command Line Output
Paste the output from your command line running `jupyter lab` here, use `--debug` if possible.
Browser Output
Paste the output from your browser Javascript console here, if applicable.

welcome[bot] commented 1 year ago

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively. welcome You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! :wave:
Welcome to the Jupyter community! :tada:

JasonWeill commented 1 year ago

At the time you ran this script, did a directory called 202306 already exist under your JupyterLab root? If so, then the error is genuine.

If you want to run a job repeatedly with this command in it, consider adding a check for the directory before you create it.

LAgeoNative commented 1 year ago

Hello,

Thank you for the response. I actually deleted the directory locally on my machine and it still thinks it exists. Is this run on somewhere else instead of it being locally?

Thanks, On Tue, Jun 6, 2023 at 2:24 PM Jason Weill @.***> wrote:

At the time you ran this script, did a directory called 202306 already exist under your JupyterLab root? If so, then the error is genuine.

If you want to run a job repeatedly with this command in it, consider adding a check for the directory before you create it.

— Reply to this email directly, view it on GitHub https://github.com/jupyter-server/jupyter-scheduler/issues/379#issuecomment-1579471251, or unsubscribe https://github.com/notifications/unsubscribe-auth/A55MGJGLREXAET7PS2CQBFTXJ6NY5ANCNFSM6AAAAAAY4UU3WE . You are receiving this because you authored the thread.Message ID: @.***>

-- Luis P. Garcia, GIS Specialist City of Los Angeles | Bureau of Street Services 1149 South Broadway, Los Angeles, CA 90015 https://maps.google.com/?q=1149+South+Broadway,+Los+Angeles,+CA+90015&entry=gmail&source=g Work Phone: (213) 847-4216

JasonWeill commented 1 year ago

I searched the web for WinError 183 and found this StackOverflow thread with a lot of examples. Deleting a file in Windows may not cause it to be removed immediately from the file system if some other process has a handle on it. (This happens with other Unix-like OSes as well, including Linux and macOS.)

You might be able to get around this in your script by checking whether the target directory already exists, and if it does, ignore the FileExistsException and continue execution.

andrii-i commented 6 months ago

Closing as solved due to absence of the follow-up from the issue author. Please feel free to follow-up if needed.