- プログラムの動作をテストするコード
- 既存のソースコードを変更した際、動作確認が必要となるが、手作業と目視で毎回確認するのはコストがかかる
- 人間は間違えたり見落としたり、サボったりするから
| import win32gui | |
| import time | |
| while True: | |
| handle = win32gui.GetForegroundWindow() | |
| title = win32gui.GetWindowText(handle) | |
| print(handle, title) | |
| time.sleep(1) |
| import socket | |
| import time | |
| import os | |
| import sys | |
| import tempfile | |
| from multiprocessing.reduction import sendfds, recvfds | |
| import unittest | |
| from unittest import TestCase |
| import thriftpy | |
| from thriftpy.thrift import TProcessor | |
| class AppServiceHandler: | |
| def echo(self, message): | |
| return message | |
| main_thrift = thriftpy.load("main.thrift") |
| import thriftpy | |
| from thriftpy.rpc import make_client | |
| tutorial_thrift = thriftpy.load( | |
| 'tutorial.thrift', module_name='tutorial_thrift') | |
| Calculator = tutorial_thrift.Calculator | |
| Work = tutorial_thrift.Work | |
| Operation = tutorial_thrift.Operation | |
| InvalidOperation = tutorial_thrift.InvalidOperation |
| import os | |
| import time | |
| import fcntl | |
| import select | |
| read_fd, write_fd = os.pipe() | |
| pid = os.fork() | |
| if pid: | |
| # 親プロセス | |
| # 読み込み側のfdは使わないのでclose |
| import os | |
| import time | |
| import fcntl | |
| import selectors | |
| read_fd, write_fd = os.pipe() | |
| pid = os.fork() | |
| if pid: | |
| # 親プロセス | |
| write_pipe = os.fdopen(write_fd, 'wb') |
| import os | |
| import sys | |
| import time | |
| import select | |
| READ_ONLY = select.EPOLLIN | |
| def main(): | |
| read_fd, write_fd = os.pipe2(os.O_NONBLOCK) | |
| pid = os.fork() |
| tokibito@ubuntu:~$ cat main.py | |
| import os | |
| import subprocess | |
| subprocess.call([os.environ['_'], "-V"]) | |
| tokibito@ubuntu:~$ python main.py | |
| Python 2.7.6 | |
| tokibito@ubuntu:~$ tmp/venv/bin/python main.py | |
| Python 3.4.3 |