http://python.kr/viewtopic.php?p=76315#76315
>>> import urllib
>>> urllib.thishost()
'192.168.10.101'
>>> import urllib
>>> urllib.thishost()
'192.168.10.101'
# the same as cygwin plus some additional parameters
class Mingw32CCompiler (CygwinCCompiler):
compiler_type = 'mingw32'
def __init__ (self,
verbose=0,
dry_run=0,
force=0):
CygwinCCompiler.__init__ (self, verbose, dry_run, force)
...................
self.set_executables(compiler='gcc -mno-cygwin -O -Wall',
compiler_so='gcc -mno-cygwin -mdll -O -Wall',
compiler_cxx='g++ -mno-cygwin -O -Wall',
linker_exe='gcc -mno-cygwin',
linker_so='%s -mno-cygwin %s %s'
% (self.linker_dll, shared_option,
entry_point))
# Maybe we should also append -mthreads, but then the finished
...................
import SocketServer
import Queue
import threading
import socket
class ThreadPoolMixIn(SocketServer.ThreadingMixIn):
'''
use a thread pool instead of a new thread on every request
'''
allow_reuse_address = True # seems to fix socket.error on server restart
def create_pool(self, numThreads):
# set up the threadpool
self.numThreads = numThreads
self.requests = Queue.Queue(self.numThreads)
self.threadPool = []
for x in range(self.numThreads):
t = threading.Thread(target = self.process_request_thread)
self.threadPool.append(t)
t.setDaemon(1)
t.start()
def process_request_thread(self):
'''
obtain request from queue instead of directly from server socket
'''
while True:
SocketServer.ThreadingMixIn.process_request_thread(self, *self.requests.get())
def process_request(self, request, client_address):
self.requests.put((request, client_address))
class ThreadPoolTCPServer(ThreadPoolMixIn, SocketServer.TCPServer):
pass
class ThreadPoolUDPServer(ThreadPoolMixIn, SocketServer.UDPServer):
pass
if __name__ == '__main__':
import SimpleHTTPServer
import SocketServer
def test(HandlerClass = SimpleHTTPServer.SimpleHTTPRequestHandler,
ServerClass = ThreadPoolTCPServer,
protocol="HTTP/1.0"):
'''
Test: Run an HTTP server on port 8002
'''
port = 8002
server_address = ('', port)
HandlerClass.protocol_version = protocol
httpd = ServerClass(server_address, HandlerClass)
httpd.create_pool(10)
sa = httpd.socket.getsockname()
print "Serving HTTP on", sa[0], "port", sa[1], "..."
httpd.serve_forever()
test()
......
import distutils.command.bdist_rpm
......
class bdist_rpm(distutils.command.bdist_rpm.bdist_rpm):
# rpm automatically byte compiles all Python files in a package but we
# don't want that to happen for initscripts and samples so we tell it to
# ignore those files
def _make_spec_file(self):
specFile = distutils.command.bdist_rpm.bdist_rpm._make_spec_file(self)
specFile.insert(0, "%define _unpackaged_files_terminate_build 0%{nil}")
return specFile
def run(self):
distutils.command.bdist_rpm.bdist_rpm.run(self)
specFile = os.path.join(self.rpm_base, "SPECS",
"%s.spec" % self.distribution.get_name())
queryFormat = "%{name}-%{version}-%{release}.%{arch}.rpm"
command = "rpm -q --qf '%s' --specfile %s" % (queryFormat, specFile)
origFileName = os.popen(command).read()
parts = origFileName.split("-")
parts.insert(2, "py%s%s" % sys.version_info[:2])
newFileName = "-".join(parts)
self.move_file(os.path.join("dist", origFileName),
os.path.join("dist", newFileName))
......
commandClasses = dict(
build_ext = build_ext,
build_scripts = build_scripts,
bdist_rpm = bdist_rpm, # 여기
install = install,
install_packagedata = install_packagedata)
.....
setup(name = "cx_Freeze",
description = "create standalone executables from Python scripts",
long_description = "create standalone executables from Python scripts",
version = "4.2",
cmdclass = commandClasses, # 여기
options = dict(bdist_rpm = dict(doc_files = docFiles),
install = dict(optimize = 1)),
ext_modules = extensions,
packages = ['cx_Freeze'],
maintainer="Anthony Tuininga",
maintainer_email="anthony.tuininga@gmail.com",
url = "http://cx-freeze.sourceforge.net",
scripts = ["cxfreeze"],
classifiers = classifiers,
keywords = "freeze",
license = "Python Software Foundation License")
........
print 'Installing data files to %s' % self.install_dir
install_data.install_data.finalize_options(self)
### 추가된 부분
import distutils.command.bdist_rpm
class bdist_rpm(distutils.command.bdist_rpm.bdist_rpm):
# rpm automatically byte compiles all Python files in a package but we
# don't want that to happen for initscripts and samples so we tell it to
# ignore those files
def _make_spec_file(self):
specFile = distutils.command.bdist_rpm.bdist_rpm._make_spec_file(self)
specFile.insert(0, "%define _unpackaged_files_terminate_build 0%{nil}")
return specFile
def run(self):
distutils.command.bdist_rpm.bdist_rpm.run(self)
specFile = os.path.join(self.rpm_base, "SPECS",
"%s.spec" % self.distribution.get_name())
queryFormat = "%{name}-%{version}-%{release}.%{arch}.rpm"
command = "rpm -q --qf '%s' --specfile %s" % (queryFormat, specFile)
origFileName = os.popen(command).read()
parts = origFileName.split("-")
parts.insert(2, "py%s%s" % sys.version_info[:2])
newFileName = "-".join(parts)
self.move_file(os.path.join("dist", origFileName),
os.path.join("dist", newFileName))
### 추가 끝부분
################################################################
# Specify the _ctypes extension
#
kw = {}
# common source files
kw["sources"] = ["source/_ctypes.c",
...........
url="http://starship.python.net/crew/theller/ctypes/",
platforms=["windows", "Linux", "MacOS X", "Solaris", "FreeBSD"],
download_url="http://sourceforge.net/project/showfiles.php?group_id=71702",
cmdclass = {'test': test, 'build_py': my_build_py, 'build_ext': my_build_ext,
'clean': my_clean, 'install_data': my_install_data,
'bdist_rpm': bdist_rpm #<< 여기
## 'ce_install_lib': ce_install_lib
},
)
## Local Variables:
## compile-command: "python setup.py build"
## End:
import time
import pywintypes
import win32file
import win32pipe
import winerror
PIPE_NAME = r"\\.\pipe\marungdb1234"
FILE_FLAG_OVERLAPPED = 0x40000000
def PipeMainThread():
print PIPE_NAME
PipeHandle = None
while 1:
if not PipeHandle:
try:
PipeHandle = win32pipe.CreateNamedPipe(PIPE_NAME,
win32pipe.PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
win32pipe.PIPE_TYPE_MESSAGE,
win32pipe.PIPE_UNLIMITED_INSTANCES,
0, 0, 3000, None)
except pywintypes.error, msg:
print msg
print msg[2]
PipeHandle = None
else:
print "Pipe Create"
if PipeHandle:
try:
hr, Str = win32file.ReadFile(PipeHandle, 4096, None)
except pywintypes.error, msg:
if msg[0] == winerror.ERROR_PIPE_LISTENING:
time.sleep(0.01)
#elif msg[0] == winerror.ERROR_BROKEN_PIPE:
# print msg
# print msg[2]
# Loop = False
else:
win32file.CloseHandle(PipeHandle)
PipeHandle = None
else:
#print hr
print Str
#self.LogSync(Str)
if PipeHandle:
win32file.CloseHandle(PipeHandle)
if __name__ == "__main__":
PipeMainThread()