This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients pitrou, serhiy.storchaka, vstinner
Date 2017-05-02.11:11:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1493723485.87.0.646779044512.issue30228@psf.upfronthosting.co.za>
In-reply-to
Content
Example:

with open("x", "w", encoding="utf-8") as fp:
    fp.write("HERE")
    fp.close()

syscalls:

14249 open("x", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0666) = 3
14249 fstat(3, {st_mode=S_IFREG|0664, st_size=0, ...}) = 0
14249 ioctl(3, TCGETS, 0x7fff07d43330)  = -1 ENOTTY (Inappropriate ioctl for device)
14249 lseek(3, 0, SEEK_CUR)             = 0
14249 lseek(3, 0, SEEK_CUR)             = 0
14249 lseek(3, 0, SEEK_CUR)             = 0
14249 write(3, "HERE", 4)               = 4
14249 close(3)                          = 0

I only expected 3 syscalls: open, write, close.

* fstat() is used by the FileIO constructor to check if the file is a directory or not, and to get the block size
* ioctl() comes from open() which checks if the file is a TTY or not, to decide how to configure buffering
* the first lseek() is used by the BuffererWriter constructor to initialize the private abs_pos attribute
* the second lseek() is used by the TextIOWrapper constructor to check if the underlying file object (buffered writer) is seekable or not
* the last lseek() is used to create the cookie object in TextIOWrapper constructor

Can we maybe reduce the number of lseek() to a single syscall?

For example, BuffererWriter constructor calls FileIO.tell(): can't this method set the seekable attribute depending on lseek() success, as the FileIO.seekable property?
History
Date User Action Args
2017-05-02 11:11:25vstinnersetrecipients: + vstinner, pitrou, serhiy.storchaka
2017-05-02 11:11:25vstinnersetmessageid: <1493723485.87.0.646779044512.issue30228@psf.upfronthosting.co.za>
2017-05-02 11:11:25vstinnerlinkissue30228 messages
2017-05-02 11:11:25vstinnercreate