I want to be able to read a windows file which is being periodically written by another process. I created a small extension which does the following

        if(!PyArg_ParseTuple(args, "sss", &fn, &mode, &deny)) return NULL;
        if(strcmp(deny, "") == 0)             share = _SH_DENYNO; /*allow all*/
        else if (strcmp(deny, "r") == 0)      share = _SH_DENYRD; /*deny read*/
        else if (strcmp(deny, "w") == 0)      share = _SH_DENYWR; /*deny write*/
        else if (strcmp(deny, "rw") == 0)     share = _SH_DENYRW; /*deny 
read/write*/
        f = _fsopen(fn, mode, share);
        if (!f){
                PyErr_SetFromErrno(PyExc_Exception);
                r = NULL;
                ERROR_EXIT();
                }
        else{
                r = PyFile_FromFile(f, fn, mode, fclose);
                if(!r) ERROR_EXIT();
                }

that seems to work, but I wonder if there's an easier pure python way to do this. Looking at the docs I see O_EXCL, but the _SH_DENY flags seem to be absent.
--
Robin Becker
_______________________________________________
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32

Reply via email to