Skip to content

Commit

Permalink
BF: pin tables==3.8.0 due to crash on Rosetta for tables==3.9.2
Browse files Browse the repository at this point in the history
Technically we could use 3.9.1 on py3.10 but easier to pin to a single version for both py3.8 and py3.10

Long-term, we need to work out why tables==3.9.2 crashes Rosetta
PyTables/PyTables#1186
  • Loading branch information
peircej committed Jul 30, 2024
1 parent ff2806b commit 1a9e418
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 43 deletions.
53 changes: 13 additions & 40 deletions psychopy/iohub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,19 @@ def _localFunc():

IOHUB_DIRECTORY = module_directory(_localFunc)

def _usingRosetta():
"""Check whether we are running under rosetta on a mac"""
if sys.platform != 'darwin' or platform.processor() != 'i386':
# platform.processor is actually the arch of binary not processor
return False
# running i386 python on mac needs more investigation
import subprocess
proc = subprocess.run(["sysctl", "-n", "sysctl.proc_translated"], capture_output=True, text=True)
if proc.returncode == 0 and proc.stdout.strip() == "1":
return True # confirmed we're using rosetta
elif proc.returncode == 0 and proc.stdout.strip() == "0":
return False # confirmed we're NOT using rosetta
else: # older macs don't have sysctl.proc_translated
print2err('WARNING: unable to determine if running under rosetta. Assuming NOT')
return False

def _haveTables():
"""Check if tables is available (if safe to try)"""
# if running rosetta (i386 python on arm64 mac) then don't *try* to import tables
# anything else we can *try* to import tables and see if it fails
if _usingRosetta():
# if we try to load the tables module on arm64 we get a seg fault
# we don't want to even try until we can work out how to detect
# in advance whether the library is arm64 or not
print2err('WARNING: running on arm64 mac which may crash loading pytables. ',
'ioHub hdf5 datastore functionality will be disabled for now.')
return False
try:
import tables
return True
except ImportError:
print2err('WARNING: pytables package not found. ',
'ioHub hdf5 datastore functionality will be disabled.')
return False
except Exception:
printExceptionDetailsToStdErr()

_DATA_STORE_AVAILABLE = _haveTables()
if _DATA_STORE_AVAILABLE:
import tables # not sure if any part of iohub needed this in the namespace
try:
import tables
_DATA_STORE_AVAILABLE = True
except ModuleNotFoundError:
print2err('WARNING: pytables package not found. ',
'ioHub hdf5 datastore functionality will be disabled.')
_DATA_STORE_AVAILABLE = False
except ImportError:
print2err('WARNING: pytables package failed to load. ',
'ioHub hdf5 datastore functionality will be disabled.')
_DATA_STORE_AVAILABLE = False
except Exception:
printExceptionDetailsToStdErr()

from psychopy.iohub.constants import EventConstants, KeyboardConstants, MouseConstants

Expand Down
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ dependencies = [
"zeroconf; platform_system == \"Darwin\"",
"python-xlib; platform_system == \"Linux\"",
"distro; platform_system == \"Linux\"",
'tables<3.9; python_version < "3.9"',
'tables; python_version >= "3.9"',
'blosc2<2.2.8; python_version < "3.9"', # dependency of tables
'tables==3.8.0', # pin to 3.8.0 until Rosetta crash fixed
"packaging>=24.1",
]

Expand Down

0 comments on commit 1a9e418

Please sign in to comment.