Ejemplo n.º 1
0
def test_getpid():
    result = None
    result = nt.getpid()
    Assert(result >= 0, "processPID should not be less than zero")

    result2 = nt.getpid()
    Assert(result2 == result, "The processPID in one process should be same")
Ejemplo n.º 2
0
def test_getpid():
    result = None
    result = nt.getpid()
    Assert(result >= 0, "processPID should not be less than zero")

    result2 = nt.getpid()
    Assert(result2 == result, "The processPID in one process should be same")
Ejemplo n.º 3
0
 def execv(filename, args):
     #  Create an O_TEMPORARY file and pass its name to the slave process.
     #  When this master process dies, the file will be deleted and the
     #  slave process will know to terminate.
     try:
         tdir = environ["TEMP"]
     except:
         tdir = None
     if tdir:
         try:
             nt.mkdir(pathjoin(tdir, "esky-slave-procs"), 0600)
         except EnvironmentError:
             pass
         if exists(pathjoin(tdir, "esky-slave-procs")):
             flags = nt.O_CREAT | nt.O_EXCL | nt.O_TEMPORARY | nt.O_NOINHERIT
             for i in xrange(10):
                 tfilenm = "slave-%d.%d.txt" % (nt.getpid(), i)
                 tfilenm = pathjoin(tdir, "esky-slave-procs", tfilenm)
                 try:
                     os_open(tfilenm, flags, 0600)
                     args.insert(1, tfilenm)
                     args.insert(1, "--esky-slave-proc")
                     break
                 except EnvironmentError:
                     pass
     # Ensure all arguments are quoted (to allow spaces in paths)
     for i, arg in enumerate(args):
         if arg[0] != '"' and args[-1] != '"':
             args[i] = '"{}"'.format(arg)
     res = spawnv(P_WAIT, filename, args)
     _exit_code[0] = res
     raise SystemExit(res)
Ejemplo n.º 4
0
 def execv(filename,args):
     #  Create an O_TEMPORARY file and pass its name to the slave process.
     #  When this master process dies, the file will be deleted and the
     #  slave process will know to terminate.
     try:
         tdir = environ["TEMP"]
     except:
         tdir = None
     if tdir:
         try:
             nt.mkdir(pathjoin(tdir,"esky-slave-procs"),0600)
         except EnvironmentError:
             pass
         if exists(pathjoin(tdir,"esky-slave-procs")):
             flags = nt.O_CREAT|nt.O_EXCL|nt.O_TEMPORARY|nt.O_NOINHERIT
             for i in xrange(10):
                 tfilenm = "slave-%d.%d.txt" % (nt.getpid(),i,)
                 tfilenm = pathjoin(tdir,"esky-slave-procs",tfilenm)
                 try:
                     os_open(tfilenm,flags,0600)
                     args.insert(1,tfilenm)
                     args.insert(1,"--esky-slave-proc")
                     break
                 except EnvironmentError:
                     pass
     # Ensure all arguments are quoted (to allow spaces in paths)
     for i, arg in enumerate(args):
         if arg[0] != "\"" and args[-1] != "\"":
             args[i] = "\"{}\"".format(arg)
     res = spawnv(P_WAIT,filename, args)
     _exit_code[0] = res
     raise SystemExit(res)
Ejemplo n.º 5
0
 def execv(filename,args):
     #  Create an O_TEMPORARY file and pass its name to the slave process.
     #  When this master process dies, the file will be deleted and the
     #  slave process will know to terminate.
     tdir = nt.environ.get("TEMP",None)
     if tdir:
         tfile = None
         try:
             nt.mkdir(pathjoin(tdir,"esky-slave-procs"))
         except EnvironmentError:
             pass
         if exists(pathjoin(tdir,"esky-slave-procs")):
             flags = nt.O_CREAT|nt.O_EXCL|nt.O_TEMPORARY|nt.O_NOINHERIT
             for i in xrange(10):
                 tfilenm = "slave-%d.%d.txt" % (nt.getpid(),i,)
                 tfilenm = pathjoin(tdir,"esky-slave-procs",tfilenm)
                 try:
                     tfile = nt.open(tfilenm,flags)
                     break
                 except EnvironmentError:
                     raise
                     pass
     if tdir and tfile:
         args.insert(1,tfilenm)
         args.insert(1,"--esky-slave-proc")
     res = spawnv(P_WAIT,filename,args)
     raise SystemExit(res)
Ejemplo n.º 6
0
 def run(self):
     print(('running', nt.getpid()))
     time.sleep(10)
     print('done running')
Ejemplo n.º 7
0
import threading, time, nt

print(('main thread', nt.getpid()))


class MyThread(threading.Thread):
    def run(self):
        print(('running', nt.getpid()))
        time.sleep(10)
        print('done running')


mt = MyThread()
mt.start()
print('joining')
mt.join()
print('done joining')
 def run(self):
     print('running', nt.getpid())
     time.sleep(10)
     print('done running')
import threading, time, nt

print ('main thread', nt.getpid())

class MyThread(threading.Thread):
    def run(self):
        print('running', nt.getpid())
        time.sleep(10)
        print('done running')


mt = MyThread()
mt.start()
print('joining')
mt.join()
print('done joining')