Re: several issues with pyinstaller on Windows 10

2021-11-18 Thread Eryk Sun
On 11/18/21, Ulli Horlacher  wrote:
>
> P:\W10\dist>argv a b
> The process cannot access the file because it is being used by another
> process.

Try searching for open handles for "argv.exe" using Sysinternals
Process Explorer [1]. Terminate the offending process.

Since you're inexperienced with Windows, here's a brief explanation of
ERROR_SHARING_VIOLATION (32).

File objects that are opened for filesystem files have a
read-write-delete sharing mode if the open requests any
read-write-delete data access, but not if the open only has metadata
access (e.g. timestamps, ID, attributes, extended attributes,
security). Note that delete access includes the right to rename a
file.

The share mode flags and associated data access rights are as follows:

FILE_SHARE_READ
- FILE_READ_DATA | FILE_EXECUTE
FILE_SHARE_WRITE
- FILE_WRITE_DATA | FILE_APPEND_DATA
FILE_SHARE_DELETE
- DELETE

For example, if an existing open for a file has any data access and
doesn't share read access, then trying to open the file with execute
access will fail as a sharing violation. The security context of the
open request doesn't matter. For example, SYSTEM and administrators
aren't privileged to bypass the sharing mode. It can only be bypassed
from the kernel.

Unfortunately the system error message for ERROR_SHARING_VIOLATION is
misleading. The sharing mode has nothing to do with processes. It's
strictly a function of the File objects that are opened for the file.

Python's open() and os.open() functions share read and write access,
but they do not share delete access. For example, overlapping calls to
open('spam.txt', 'w') are allowed. For os.stat(), the share mode of
existing opens doesn't matter because it opens the file with metadata
access only.

Sharing data access can get messy. Each open has its own file pointer
in the associated OS file object. For example, say an open writes 10
bytes and flushes the buffer. Then a second open(..., 'w') call
overwrites the file, truncating it to 0 bytes. When the original open
writes to the file again, the OS will back fill the file with 10 null
bytes.

Windows also provides byte-range shared and exclusive locking that can
exceed the current size of the file. A byte-range lock doesn't prevent
opening the file with read, write, or delete access, and it doesn't
prevent deleting the file. It causes write or read-write operations on
the range to fail with ERROR_LOCK_VIOLATION (33).

> win32ctypes.pywin32.pywintypes.error: (110, 'EndUpdateResourceW',
> 'The system cannot open the device or file specified.')

This is likely due to a sharing violation. EndUpdateResourceW() [2]
requires exclusive access to the target file. If its internal open
fails for any reason, it maps all errors to this generic
ERROR_OPEN_FAILED (110) error code.

---
[1] https://docs.microsoft.com/en-us/sysinternals/downloads/process-explorer
[2] 
https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-endupdateresourcew
-- 
https://mail.python.org/mailman/listinfo/python-list


several issues with pyinstaller on Windows 10

2021-11-18 Thread Ulli Horlacher
On Windows 10 I have installed:

P:\W10>python --version
Python 3.10.0

P:\W10>pyinstaller --version
4.7

I can compile a VERY simple Python program:

P:\W10>type argv.pv
#!/usr/bin/python3

import sys

for a in sys.argv: print("["+a+"]")


P:\W10>pyinstaller.exe --onefile tcpbm.py

But I can run it only once:

P:\W10\dist>argv a b
[dist\argv]
[a]
[b]

P:\W10\dist>argv a b
The process cannot access the file because it is being used by another process.

P:\W10\dist>argv 1 2 zzz
The process cannot access the file because it is being used by another process.


Compiling a little more complex program (with net IO) fails:

P:\W10>pyinstaller.exe --onefile tcpbm.py
140 INFO: PyInstaller: 4.7
140 INFO: Python: 3.10.0
171 INFO: Platform: Windows-10-10.0.19041-SP0
171 INFO: wrote P:\W10\tcpbm.spec
171 INFO: UPX is not available.
203 INFO: Extending PYTHONPATH with paths
['P:\\W10']
531 INFO: checking Analysis
547 INFO: Building Analysis because Analysis-00.toc is non existent
547 INFO: Initializing module dependency graph...
562 INFO: Caching module graph hooks...
593 INFO: Analyzing base_library.zip ...
4656 INFO: Processing pre-find module path hook distutils from 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
4656 INFO: distutils: retargeting to non-venv dir 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib'
5781 INFO: Caching module dependency graph...
6031 INFO: running Analysis Analysis-00.toc
6031 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of 
final executable
  required by C:\Users\admin\AppData\Local\Programs\Python\Python310\python.exe
6187 INFO: Analyzing P:\W10\tcpbm.py
6250 INFO: Processing module hooks...
6250 INFO: Loading module hook 'hook-difflib.py' from 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6250 INFO: Loading module hook 'hook-distutils.py' from 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6250 INFO: Loading module hook 'hook-distutils.util.py' from 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6250 INFO: Loading module hook 'hook-encodings.py' from 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6390 INFO: Loading module hook 'hook-heapq.py' from 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6390 INFO: Loading module hook 'hook-lib2to3.py' from 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6484 INFO: Loading module hook 'hook-multiprocessing.util.py' from 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6484 INFO: Loading module hook 'hook-pickle.py' from 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6484 INFO: Loading module hook 'hook-sysconfig.py' from 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6484 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6500 INFO: Loading module hook 'hook-xml.py' from 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6546 INFO: Loading module hook 'hook-_tkinter.py' from 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks'...
6734 INFO: checking Tree
6734 INFO: Building Tree because Tree-00.toc is non existent
6749 INFO: Building Tree Tree-00.toc
6890 INFO: checking Tree
6890 INFO: Building Tree because Tree-01.toc is non existent
6890 INFO: Building Tree Tree-01.toc
7031 INFO: checking Tree
7031 INFO: Building Tree because Tree-02.toc is non existent
7031 INFO: Building Tree Tree-02.toc
7062 INFO: Looking for ctypes DLLs
7078 INFO: Analyzing run-time hooks ...
7093 INFO: Including run-time hook 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgutil.py'
7093 INFO: Including run-time hook 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
7109 INFO: Including run-time hook 
'C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_inspect.py'
7109 INFO: Looking for dynamic libraries
7546 INFO: Looking for eggs
7546 INFO: Using Python library
C:\Users\admin\AppData\Local\Programs\Python\Python310\python310.dll
7562 INFO: Found binding redirects:
[]
7562 INFO: Warnings written to P:\W10\build\tcpbm\warn-tcpbm.txt
76