Giter Site home page Giter Site logo

Comments (6)

takluyver avatar takluyver commented on September 26, 2024

It's easy enough to start multiple processes to run at the same time, but pexpect can currently only wait for a pattern on one spawned process at a time. I've been thinking about integrating it with asyncio to make this kind of thing easier.

from pexpect.

calbare avatar calbare commented on September 26, 2024

Thanks, do you have any idea on when this would happen? Also, does pexpect only work for python2 (not 3)? Thanks.

from pexpect.

takluyver avatar takluyver commented on September 26, 2024

It's not an immediate plan, I'm afraid. Pexpect does work on Python 2 and 3, though.

from pexpect.

takluyver avatar takluyver commented on September 26, 2024

Sourceforge feature request 5 asked for the same thing:

There is a feature of TCL-expect that I really miss on pexpect: being able to wait on a number of spawn children within a single command. I guess my way of better describing it would be by example:

child1 = pexpect.spawn ('ftp site1.org')
child2 = pexpect.spawn ('ftp site2.org')
child3 = pexpect.spawn ('ftp site3.org')

strExpect = 'Name .*: '

result, childMatch = expectSelect( (child1, strExpect), (child2, strExpect), (child3, strExpect) )

if not result:
    print "timed out on all children"

if (childMatch == 1):
    print "matched on child 1"

The main idea of this feature request is that we obtain a select behavior such that a single execution thread can continue as soon as the first match (or timeout) takes place in any of the children in a list provided.

TCL expect allows for that by providing a list of spawned ids in the -i flag. This is extremely useful
for performance reasons when dealing with multiple children that are spawned concurrently.

Thanks!

from pexpect.

jquast avatar jquast commented on September 26, 2024

asyncio in upcoming release. This implements a Waiter pattern, but no such feature (multiplexing over multiple children) is provided.

from pexpect.

takluyver avatar takluyver commented on September 26, 2024

With an asyncio future interface, I think you should be able to multiplex over multiple child processes using functions in asyncio like asyncio.wait().

I haven't tried, but it should be something like this:

done, pending = yield from asyncio.wait([
    p1.expect('foo', async=True),
    p2.expect('bar', async=True)
], timeout=20, return_when=concurrent.futures.FIRST_COMPLETED)

from pexpect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.