Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all test_socket.py tests fail with python3.8 #665

Open
nieder opened this issue Nov 26, 2020 · 2 comments
Open

all test_socket.py tests fail with python3.8 #665

nieder opened this issue Nov 26, 2020 · 2 comments

Comments

@nieder
Copy link

nieder commented Nov 26, 2020

On macOS 10.13, all tests from test_socket.py fail when tested using python3.8. python2.7 and python3.4-3.7 pass OK.

All the errors exit with an error similar to:

_______________________________________________________ ExpectTestCase.test_stdin_closed ________________________________________________________

self = <tests.test_expect.ExpectTestCase testMethod=test_stdin_closed>

    def test_stdin_closed(self):
        '''
        Ensure pexpect continues to operate even when stdin is closed
        '''
        class Closed_stdin_proc(multiprocessing.Process):
            def run(self):
                sys.__stdin__.close()
                cat = pexpect.spawn('cat')
                cat.sendeof()
                cat.expect(pexpect.EOF)
    
        proc = Closed_stdin_proc()
>       proc.start()

tests/test_expect.py:584: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/sw/lib/python3.8/multiprocessing/process.py:121: in start
    self._popen = self._Popen(self)
/sw/lib/python3.8/multiprocessing/context.py:224: in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
/sw/lib/python3.8/multiprocessing/context.py:284: in _Popen
    return Popen(process_obj)
/sw/lib/python3.8/multiprocessing/popen_spawn_posix.py:32: in __init__
    super().__init__(process_obj)
/sw/lib/python3.8/multiprocessing/popen_fork.py:19: in __init__
    self._launch(process_obj)
/sw/lib/python3.8/multiprocessing/popen_spawn_posix.py:47: in _launch
    reduction.dump(process_obj, fp)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

obj = <Closed_stdin_proc name='Closed_stdin_proc-1' parent=2647 initial>, file = <_io.BytesIO object at 0x10aa334f0>, protocol = None

    def dump(obj, file, protocol=None):
        '''Replacement for pickle.dump() using ForkingPickler.'''
>       ForkingPickler(file, protocol).dump(obj)
E       AttributeError: Can't pickle local object 'ExpectTestCase.test_stdin_closed.<locals>.Closed_stdin_proc'

/sw/lib/python3.8/multiprocessing/reduction.py:60: AttributeError
------------------------------------------------------------- Captured stdout call --------------------------------------------------------------

 tests.test_expect.ExpectTestCase.test_stdin_closed 
@dmacks
Copy link

dmacks commented Feb 4, 2022

Likewise on newer pythons (tried py3.10 on OS X 10.13).

@nieder
Copy link
Author

nieder commented Jan 20, 2024

--- pexpect/__init__.py-orig	2024-01-20 07:50:39
+++ pexpect/__init__.py	2024-01-20 07:50:43
@@ -70,6 +70,7 @@
 '''
 
 import sys
+import multiprocessing
 PY3 = (sys.version_info[0] >= 3)
 
 from .exceptions import ExceptionPexpect, EOF, TIMEOUT
@@ -81,6 +82,9 @@
     from .pty_spawn import spawn, spawnu
     from .run import run, runu
 
+if sys.platform.startswith('darwin'):
+    multiprocessing.set_start_method('fork')
+
 __version__ = '4.9.0'
 __revision__ = ''
 __all__ = ['ExceptionPexpect', 'EOF', 'TIMEOUT', 'spawn', 'spawnu', 'run', 'runu',

cf kevlened/pytest-parallel#41 . Not sure how safe this actually is, however.

kevlened/pytest-parallel@9c69c4e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants