File: processes.py

package info (click to toggle)
python-gevent 24.11.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,364 kB
  • sloc: python: 138,768; ansic: 87,807; sh: 12,548; makefile: 2,379; javascript: 108
file content (32 lines) | stat: -rwxr-xr-x 714 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
from __future__ import print_function
import gevent
from gevent import subprocess

import sys

if sys.platform.startswith('win'):
    UNAME = ['cmd.exe', '/C', 'ver']
    LS = ['dir.exe']
else:
    UNAME = ['uname']
    LS = ['ls']

# run 2 jobs in parallel
p1 = subprocess.Popen(UNAME, stdout=subprocess.PIPE)
p2 = subprocess.Popen(LS, stdout=subprocess.PIPE)

gevent.wait([p1, p2], timeout=2)

# print the results (if available)
if p1.poll() is not None:
    print('uname: %r' % p1.stdout.read())
else:
    print('uname: job is still running')
if p2.poll() is not None:
    print('ls: %r' % p2.stdout.read())
else:
    print('ls: job is still running')

p1.stdout.close()
p2.stdout.close()