beeware / Python-Apple-support

A meta-package for building a version of Python that can be embedded into a macOS, iOS, tvOS or watchOS project.
MIT License
1.11k stars 160 forks source link

AttributeError: 'module' object has no attribute 'waitpid' #80

Closed AnissaHum closed 4 years ago

AnissaHum commented 4 years ago

I tried to run my code with the following app_packages : six and ipaddress. I get this following error when I try to import subprocess inside my Python code

freakboy3742 commented 4 years ago

Moving ticket to Python-Apple-support since this isn't an issue with the application template.

It's difficult to diagnose further without a full stack trace; however, you should be aware that iOS has a number of restrictions related to subprocesses - in short, you can't use them. An iOS app can be multi-threaded, but it can't be multi-process, and there's no concept of cross-process communication (well - there is a very restricted channel for resource sharing, but it's not anything like the "unix pipe" sense of the word).

In short, If you're trying to import subprocess on iOS, you're going to have a bad time.

AnissaHum commented 4 years ago

Thank you for your answer. If ever someone gets the same issue : the problem is that iOS cannot run functions of subprocess module because it uses linux-based functions (which are not available in iOS). My app is actually used on both platforms : iOS and Linux, that is why I was trying to import subprocess. You should configure your app to not run functions that use subprocess functions. You can in addition do

try: 
     import subprocess
except ImportError as e:
     pass