Python Data Science Jobs & Interviews
20.6K subscribers
192 photos
4 videos
25 files
334 links
Your go-to hub for Python and Data Science—featuring questions, answers, quizzes, and interview tips to sharpen your skills and boost your career in the data-driven world.

Admin: @Hussein_Sheikho
Download Telegram
⁉️ Interview question
Can you explain the behavior of Python’s shutil.copyfile() when copying a file that is currently being written to by another process, and how does the underlying system call interact with file locks and inodes? What happens if the source file is deleted during the copy?

When `shutil.copyfile()` copies a file that's actively being written to, it reads the file at the moment the system call opens it. If the source file is deleted during the copy, the file may still be accessible as long as it remains open by the writing process due to Unix-like filesystem semantics (file deletion doesn't free inode until all references are closed). However, the copy operation might fail or produce incomplete data if the file size changes dramatically during the read. Additionally, if the source uses mandatory locking, the copy could be blocked or result in EACCES errors.

#️⃣ tags: #Python #AdvancedPython #FileHandling #shutil #SystemCalls #FileLocks #Inodes #Unix #ConcurrentWriting #CopyOperation #FileDeletion

By: t.iss.one/DataScienceQ 🚀
⁉️ Interview question
What happens when you use os.link() to create a hard link to a file that is already open in write mode by another process, and how does this affect the file’s inode reference count, data integrity, and potential for race conditions during deletion?

Creating a hard link via `os.link()` increases the inode reference count, meaning the file won’t be deleted until all links are removed. However, if the original file is being written to, the new link points to the same underlying data blocks. If the original file is truncated or deleted while the link exists, the data remains accessible through the link until all processes close it. This can lead to data inconsistency if the writing process modifies the file size but the link still references old data. Additionally, concurrent operations on the same inode without proper synchronization may cause corruption or unexpected behavior.

#️⃣ tags: #Python #AdvancedPython #FileHandling #HardLink #Inode #OS #RaceCondition #DataIntegrity #FileOperations #SystemCalls #Linux #FileDeletion

By: t.iss.one/DataScienceQ 🚀