comparison unix.py @ 136:ed4035661b85

Added a C implementation of the unix module (called _unix)
author Oleg Oshmyan <chortos@inbox.lv>
date Tue, 24 May 2011 20:51:01 +0100
parents e84f33a60a5c
children
comparison
equal deleted inserted replaced
135:523ba6907f3a 136:ed4035661b85
22 SIGTERM = 15 22 SIGTERM = 15
23 SIGKILL = 9 23 SIGKILL = 9
24 24
25 __all__ = 'call', 'kill', 'pause', 'clock' 25 __all__ = 'call', 'kill', 'pause', 'clock'
26 26
27
28 if not sys.stdin.isatty():
29 pause = lambda: sys.stdin.read(1)
30 catch_escape = False
31 else:
32 try:
33 from select import select
34 import termios, tty, atexit
35 except ImportError:
36 pause = None
37 catch_escape = False
38 else:
39 catch_escape = True
40 def cleanup(old=termios.tcgetattr(sys.stdin.fileno())):
41 termios.tcsetattr(sys.stdin.fileno(), termios.TCSAFLUSH, old)
42 atexit.register(cleanup)
43 tty.setcbreak(sys.stdin.fileno())
44 def pause():
45 sys.stdin.read(1)
46 27
47 try: 28 try:
48 from signal import SIGCHLD, SIG_DFL, signal, set_wakeup_fd 29 from signal import SIGCHLD, SIG_DFL, signal, set_wakeup_fd
49 from select import select, error as SelectError 30 from select import select, error as SelectError
50 from errno import EAGAIN, EINTR 31 from errno import EAGAIN, EINTR
305 try: 286 try:
306 return process.wait() 287 return process.wait()
307 except OSError: 288 except OSError:
308 if sys.exc_info()[1].errno != EINTR: 289 if sys.exc_info()[1].errno != EINTR:
309 raise 290 raise
291
292
293 try:
294 from _unix import *
295 except ImportError:
296 if not sys.stdin.isatty():
297 pause = lambda: sys.stdin.read(1)
298 catch_escape = False
299 else:
300 try:
301 from select import select
302 import termios, tty, atexit
303 except ImportError:
304 pause = lambda: sys.stdin.read(1)
305 catch_escape = False
306 else:
307 catch_escape = True
308 def cleanup(old=termios.tcgetattr(sys.stdin.fileno())):
309 termios.tcsetattr(sys.stdin.fileno(), termios.TCSAFLUSH, old)
310 atexit.register(cleanup)
311 tty.setcbreak(sys.stdin.fileno())
312 def pause():
313 sys.stdin.read(1)