All Samples(2339) | Call(2226) | Derive(0) | Import(113)
ctime(seconds) -> string Convert a time in seconds since the Epoch to a string in local time. This is equivalent to asctime(localtime(seconds)). When the time tuple is not present, current time as returned by localtime() is used.
src/p/r/practice_python-HEAD/bookexample/src/bvista/mtsleep4.py practice_python(Download)
''' import threading from time import sleep, ctime loops = [4,2]
def loop(nloop, nsec):
print 'start loop', nloop, 'at:', ctime( )
sleep(nsec)
print 'loop', nloop, 'done at:', ctime( )
def main():
print 'starting at:', ctime(seconds)
for i in nloops:
threads[i].join()
print 'all DONE at:', ctime()
if __name__ == '__main__':
main()
src/p/r/practice_python-HEAD/bookexample/src/bvista/b15_2_gendata.py practice_python(Download)
from random import randint, choice
from string import lowercase
from sys import maxint
from time import ctime
doms = ('com', 'edu', 'net', 'org', 'gov')
for i in range(randint(5, 10)):
dtint = randint(0, maxint-1)
ctime(dtint)
src/p/r/practice_python-HEAD/bookexample/src/bvista/mtsleep1.py practice_python(Download)
'''
import thread
from time import sleep, ctime
def loop0():
print 'start loop 0 at:', ctime()
sleep(4)
print 'loop 0 at:', ctime( )
def loop1():
print 'start loop1 at:', ctime()
sleep(2)
print 'loop 1 done at:', ctime( )
def main():
print 'starting at:', ctime( )
thread.start_new(loop0, ())
thread.start_new(loop1, ())
sleep(6)
print 'all DONE at:', ctime( )
src/p/r/practice_python-HEAD/bookexample/src/bvista/b18_1_onethr.py practice_python(Download)
'''
from time import sleep, ctime
def loop0():
print 'start loop 0 at:', ctime()
sleep(4)
print 'loop 0 done at:', ctime()
def loop1():
print 'start loop 1 at:', ctime()
sleep(2)
print 'loop 1 done at:', ctime()
def main():
print 'starting at:', ctime()
loop0()
loop1()
print 'all DONE at:', ctime()
if __name__ == '__main__':
src/p/r/practice_python-HEAD/bookexample/src/bvista/mtsleep5.py practice_python(Download)
''' import threading from time import sleep, ctime loops = (4,2)
def loop(nloop, nsec):
print 'start loop', nloop, 'at:', ctime( )
sleep(nsec)
print 'loop', nloop, 'done at:', ctime()
def main():
print 'starting at', ctime()
for i in nloops:
threads[i].join()
print 'all DONE at:', ctime()
if __name__ == '__main__':
main()
src/p/r/practice_python-HEAD/bookexample/src/bvista/mtsleep2.py practice_python(Download)
'''
import thread
from time import sleep, ctime
loops = [4,2]
def loop(nloop, nsec, lock):
print 'start loop', nloop, 'at:', ctime( )
sleep(nsec)
print 'loop', nloop, 'done at:', ctime( )
def main():
print 'starting at:', ctime( )
locks = []
nloops = range(len(loops))
for i in nloops:
lock = thread.allocate_lock()
for i in nloops:
while locks[i].locked():
pass
print 'all DONE at:', ctime( )
if __name__ == '__main__':
main()src/p/r/practice_python-HEAD/bookexample/src/bvista/b18_4_mtsleep3.py practice_python(Download)
'''
import threading
from time import sleep, ctime
loops = [4,2]
def loop(nloop, nsec):
print 'start loop', nloop, 'at:', ctime()
sleep(nsec)
print 'loop', nloop, 'done at:', ctime( )
def main():
print 'starting at:', ctime( )
for i in nloops:
threads[i].join()
print 'all DONE at:', ctime( )
if __name__ == '__main__':
main()
src/p/r/practice_python-HEAD/bookexample/src/bvista/myThread.py practice_python(Download)
'''
import threading
from time import ctime
class MyThread(threading.Thread):
def __init__(self, func, args, name=''):
def run(self):
print 'starting', self.name, 'at:', ctime( )
self.res = apply(self.func, self.args)
print self.name, 'finished at:', ctime( )src/p/r/practice_python-HEAD/bookexample/src/bvista/b16_5_ts_tservSS.py practice_python(Download)
'''
from SocketServer import (TCPServer as TCP, StreamRequestHandler as SRH)
from time import ctime
HOST = ''
PORT = 21567
ADDR = (HOST, PORT)
class MyRequestHandler(SRH):
def handle(self):
print '...connected from:', self.client_address
self.wfile.write('[%s] %s' % (ctime(), self.rfile.readline()))
src/p/r/practice_python-HEAD/bookexample/src/bvista/b16_3_ts_userv.py practice_python(Download)
''' from socket import * from time import ctime HOST = '' PORT = 21567
while True:
print 'waiting for message ...'
data, addr = udp_ser_sock.recvfrom(BUFSIZ)
udp_ser_sock.sendto('[%s] %s' % (ctime( ), data), addr)
print '...received from and return to:', addr
udp_ser_sock.close()1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Next