Comments (6)
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.
Thanks, do you have any idea on when this would happen? Also, does pexpect only work for python2 (not 3)? Thanks.
from pexpect.
It's not an immediate plan, I'm afraid. Pexpect does work on Python 2 and 3, though.
from pexpect.
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.
asyncio in upcoming release. This implements a Waiter pattern, but no such feature (multiplexing over multiple children) is provided.
from pexpect.
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)
- Support for new release HOT 3
- Two tests hang on `cat` HOT 3
- test_large_stdout_stream timeout HOT 1
- REPLWrapTestCase.test_existing_spawn fail on illumos HOT 1
- sdist is missing requirements-testing.txt
- AttributeError: module 'asyncio' has no attribute 'coroutine' HOT 1
- Incorrect DEVELOPERS.rst
- False positive expect_exact HOT 1
- Test REPLWrapTestCase.test_pager_as_cat fails.
- An asterisk appearing out of nowhere with Clojure
- Time for a release: any reason to delay? HOT 5
- 4.9.0: git tag does not match PyPI version HOT 2
- Handling SIGTSTP possible?
- Docs not updated for 4.9?
- 4.9: pytest fails in 3 units HOT 1
- "expect()" and "await expect()" have different results on completed processes
- Pexpect does not implement enough asynchronous methods to prevent the use of time.sleep().
- add contribution documentation
- Pxssh sometime does not capture the full output of previous `sendline`
- trouble using pexpect with julia
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pexpect.