操作系统导论-py2文件修改为py3文件快捷解决方法

2024-03-28 13:36

本文主要是介绍操作系统导论-py2文件修改为py3文件快捷解决方法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

在操作系统导论作业中,我们需要用到HW文件。但是这个代码包中,所有.py文件都是py2格式的,需要我们修改为py3文件后运行,即将.py文件开头的

#! /usr/bin/env python

修改为:

#! /usr/bin/env python3

在前面小部分文件中,这样就解决问题了。但后续的大部分文件,包含了大量的print语句。众所周知,py2和py3的print语句格式是不一样的,后者比前者多了一个括号()。这时候不少同学就开始手动修改代码,这也不失为一种方法。但是,我们也可以使用一些神奇的库函数修改。

 

比如如下py2代码:

#! /usr/bin/env pythonimport sys
from optparse import OptionParser
import random# finds the highest nonempty queue
# -1 if they are all empty
def FindQueue():q = hiQueuewhile q > 0:if len(queue[q]) > 0:return qq -= 1if len(queue[0]) > 0:return 0return -1def Abort(str):sys.stderr.write(str + '\n')exit(1)#
# PARSE ARGUMENTS
#parser = OptionParser()
parser.add_option('-s', '--seed', help='the random seed', default=0, action='store', type='int', dest='seed')
parser.add_option('-n', '--numQueues',help='number of queues in MLFQ (if not using -Q)', default=3, action='store', type='int', dest='numQueues')
parser.add_option('-q', '--quantum', help='length of time slice (if not using -Q)',default=10, action='store', type='int', dest='quantum')
parser.add_option('-a', '--allotment', help='length of allotment (if not using -A)',default=1, action='store', type='int', dest='allotment')
parser.add_option('-Q', '--quantumList',help='length of time slice per queue level, specified as ' + \'x,y,z,... where x is the quantum length for the highest ' + \'priority queue, y the next highest, and so forth', default='', action='store', type='string', dest='quantumList')
parser.add_option('-A', '--allotmentList',help='length of time allotment per queue level, specified as ' + \'x,y,z,... where x is the # of time slices for the highest ' + \'priority queue, y the next highest, and so forth', default='', action='store', type='string', dest='allotmentList')
parser.add_option('-j', '--numJobs', default=3, help='number of jobs in the system',action='store', type='int', dest='numJobs')
parser.add_option('-m', '--maxlen', default=100, help='max run-time of a job ' +'(if randomly generating)', action='store', type='int',dest='maxlen')
parser.add_option('-M', '--maxio', default=10,help='max I/O frequency of a job (if randomly generating)',action='store', type='int', dest='maxio')
parser.add_option('-B', '--boost', default=0,help='how often to boost the priority of all jobs back to ' +'high priority', action='store', type='int', dest='boost')
parser.add_option('-i', '--iotime', default=5,help='how long an I/O should last (fixed constant)',action='store', type='int', dest='ioTime')
parser.add_option('-S', '--stay', default=False,help='reset and stay at same priority level when issuing I/O',action='store_true', dest='stay')
parser.add_option('-I', '--iobump', default=False,help='if specified, jobs that finished I/O move immediately ' + \'to front of current queue',action='store_true', dest='iobump')
parser.add_option('-l', '--jlist', default='',help='a comma-separated list of jobs to run, in the form ' + \'x1,y1,z1:x2,y2,z2:... where x is start time, y is run ' + \'time, and z is how often the job issues an I/O request',action='store', type='string', dest='jlist')
parser.add_option('-c', help='compute answers for me', action='store_true',default=False, dest='solve')(options, args) = parser.parse_args()random.seed(options.seed)# MLFQ: How Many Queues
numQueues = options.numQueuesquantum = {}
if options.quantumList != '':# instead, extract number of queues and their time slicquantumLengths = options.quantumList.split(',')numQueues = len(quantumLengths)qc = numQueues - 1for i in range(numQueues):quantum[qc] = int(quantumLengths[i])qc -= 1
else:for i in range(numQueues):quantum[i] = int(options.quantum)allotment = {}
if options.allotmentList != '':allotmentLengths = options.allotmentList.split(',')if numQueues != len(allotmentLengths):print('number of allotments specified must match number of quantums')exit(1)qc = numQueues - 1for i in range(numQueues):allotment[qc] = int(allotmentLengths[i])if qc != 0 and allotment[qc] <= 0:print('allotment must be positive integer')exit(1)qc -= 1
else:for i in range(numQueues):allotment[i] = int(options.allotment)hiQueue = numQueues - 1# MLFQ: I/O Model
# the time for each IO: not great to have a single fixed time but...
ioTime = int(options.ioTime)# This tracks when IOs and other interrupts are complete
ioDone = {}# This stores all info about the jobs
job = {}# seed the random generator
random.seed(options.seed)# jlist 'startTime,runTime,ioFreq:startTime,runTime,ioFreq:...'
jobCnt = 0
if options.jlist != '':allJobs = options.jlist.split(':')for j in allJobs:jobInfo = j.split(',')if len(jobInfo) != 3:print('Badly formatted job string. Should be x1,y1,z1:x2,y2,z2:...')print('where x is the startTime, y is the runTime, and z is the I/O frequency.')exit(1)assert(len(jobInfo) == 3)startTime = int(jobInfo[0])runTime   = int(jobInfo[1])ioFreq    = int(jobInfo[2])job[jobCnt] = {'currPri':hiQueue, 'ticksLeft':quantum[hiQueue],'allotLeft':allotment[hiQueue], 'startTime':startTime,'runTime':runTime, 'timeLeft':runTime, 'ioFreq':ioFreq, 'doingIO':False,'firstRun':-1}if startTime not in ioDone:ioDone[startTime] = []ioDone[startTime].append((jobCnt, 'JOB BEGINS'))jobCnt += 1
else:# do something randomfor j in range(options.numJobs):startTime = 0runTime   = int(random.random() * (options.maxlen - 1) + 1)ioFreq    = int(random.random() * (options.maxio - 1) + 1)job[jobCnt] = {'currPri':hiQueue, 'ticksLeft':quantum[hiQueue],'allotLeft':allotment[hiQueue], 'startTime':startTime,'runTime':runTime, 'timeLeft':runTime, 'ioFreq':ioFreq, 'doingIO':False,'firstRun':-1}if startTime not in ioDone:ioDone[startTime] = []ioDone[startTime].append((jobCnt, 'JOB BEGINS'))jobCnt += 1numJobs = len(job)print 'Here is the list of inputs:'
print 'OPTIONS jobs',            numJobs
print 'OPTIONS queues',          numQueues
for i in range(len(quantum)-1,-1,-1):print 'OPTIONS allotments for queue %2d is %3d' % (i, allotment[i])print 'OPTIONS quantum length for queue %2d is %3d' % (i, quantum[i])
print 'OPTIONS boost',           options.boost
print 'OPTIONS ioTime',          options.ioTime
print 'OPTIONS stayAfterIO',     options.stay
print 'OPTIONS iobump',          options.iobumpprint '\n'
print 'For each job, three defining characteristics are given:'
print '  startTime : at what time does the job enter the system'
print '  runTime   : the total CPU time needed by the job to finish'
print '  ioFreq    : every ioFreq time units, the job issues an I/O'
print '              (the I/O takes ioTime units to complete)\n'print 'Job List:'
for i in range(numJobs):print '  Job %2d: startTime %3d - runTime %3d - ioFreq %3d' % (i, job[i]['startTime'],job[i]['runTime'],job[i]['ioFreq'])
print ''if options.solve == False:print 'Compute the execution trace for the given workloads.'print 'If you would like, also compute the response and turnaround'print 'times for each of the jobs.'print ''print 'Use the -c flag to get the exact results when you are finished.\n'exit(0)# initialize the MLFQ queues
queue = {}
for q in range(numQueues):queue[q] = []# TIME IS CENTRAL
currTime = 0# use these to know when we're finished
totalJobs    = len(job)
finishedJobs = 0print '\nExecution Trace:\n'while finishedJobs < totalJobs:# find highest priority job# run it until either# (a) the job uses up its time quantum# (b) the job performs an I/O# check for priority boostif options.boost > 0 and currTime != 0:if currTime % options.boost == 0:print '[ time %d ] BOOST ( every %d )' % (currTime, options.boost)# remove all jobs from queues (except high queue) and put them in high queuefor q in range(numQueues-1):for j in queue[q]:if job[j]['doingIO'] == False:queue[hiQueue].append(j)queue[q] = []# change priority to high priority# reset number of ticks left for all jobs (just for lower jobs?)# add to highest run queue (if not doing I/O)for j in range(numJobs):# print '-> Boost %d (timeLeft %d)' % (j, job[j]['timeLeft'])if job[j]['timeLeft'] > 0:# print '-> FinalBoost %d (timeLeft %d)' % (j, job[j]['timeLeft'])job[j]['currPri']   = hiQueuejob[j]['ticksLeft'] = allotment[hiQueue]# print 'BOOST END: QUEUES look like:', queue# check for any I/Os doneif currTime in ioDone:for (j, type) in ioDone[currTime]:q = job[j]['currPri']job[j]['doingIO'] = Falseprint '[ time %d ] %s by JOB %d' % (currTime, type, j)if options.iobump == False or type == 'JOB BEGINS':queue[q].append(j)else:queue[q].insert(0, j)# now find the highest priority jobcurrQueue = FindQueue()if currQueue == -1:print '[ time %d ] IDLE' % (currTime)currTime += 1continue# there was at least one runnable job, and hence ...currJob = queue[currQueue][0]if job[currJob]['currPri'] != currQueue:Abort('currPri[%d] does not match currQueue[%d]' % (job[currJob]['currPri'], currQueue))job[currJob]['timeLeft']  -= 1job[currJob]['ticksLeft'] -= 1if job[currJob]['firstRun'] == -1:job[currJob]['firstRun'] = currTimerunTime   = job[currJob]['runTime']ioFreq    = job[currJob]['ioFreq']ticksLeft = job[currJob]['ticksLeft']allotLeft = job[currJob]['allotLeft']timeLeft  = job[currJob]['timeLeft']print '[ time %d ] Run JOB %d at PRIORITY %d [ TICKS %d ALLOT %d TIME %d (of %d) ]' % \(currTime, currJob, currQueue, ticksLeft, allotLeft, timeLeft, runTime)if timeLeft < 0:Abort('Error: should never have less than 0 time left to run')# UPDATE TIMEcurrTime += 1# CHECK FOR JOB ENDINGif timeLeft == 0:print '[ time %d ] FINISHED JOB %d' % (currTime, currJob)finishedJobs += 1job[currJob]['endTime'] = currTime# print 'BEFORE POP', queuedone = queue[currQueue].pop(0)# print 'AFTER POP', queueassert(done == currJob)continue# CHECK FOR IOissuedIO = Falseif ioFreq > 0 and (((runTime - timeLeft) % ioFreq) == 0):# time for an IO!print '[ time %d ] IO_START by JOB %d' % (currTime, currJob)issuedIO = Truedesched = queue[currQueue].pop(0)assert(desched == currJob)job[currJob]['doingIO'] = True# this does the bad rule -- reset your tick counter if you stay at the same levelif options.stay == True:job[currJob]['ticksLeft'] = quantum[currQueue]job[currJob]['allotLeft'] = allotment[currQueue]# add to IO Queue: but which queue?futureTime = currTime + ioTimeif futureTime not in ioDone:ioDone[futureTime] = []print 'IO DONE'ioDone[futureTime].append((currJob, 'IO_DONE'))# CHECK FOR QUANTUM ENDING AT THIS LEVEL (BUT REMEMBER, THERE STILL MAY BE ALLOTMENT LEFT)if ticksLeft == 0:if issuedIO == False:# IO HAS NOT BEEN ISSUED (therefor pop from queue)'desched = queue[currQueue].pop(0)assert(desched == currJob)job[currJob]['allotLeft'] = job[currJob]['allotLeft'] - 1if job[currJob]['allotLeft'] == 0:# this job is DONE at this level, so move onif currQueue > 0:# in this case, have to change the priority of the jobjob[currJob]['currPri']   = currQueue - 1job[currJob]['ticksLeft'] = quantum[currQueue-1]job[currJob]['allotLeft'] = allotment[currQueue-1]if issuedIO == False:queue[currQueue-1].append(currJob)else:job[currJob]['ticksLeft'] = quantum[currQueue]job[currJob]['allotLeft'] = allotment[currQueue]if issuedIO == False:queue[currQueue].append(currJob)else:# this job has more time at this level, so just push it to endjob[currJob]['ticksLeft'] = quantum[currQueue]if issuedIO == False:queue[currQueue].append(currJob)# print out statistics
print ''
print 'Final statistics:'
responseSum   = 0
turnaroundSum = 0
for i in range(numJobs):response   = job[i]['firstRun'] - job[i]['startTime']turnaround = job[i]['endTime'] - job[i]['startTime']print '  Job %2d: startTime %3d - response %3d - turnaround %3d' % (i, job[i]['startTime'],response, turnaround)responseSum   += responseturnaroundSum += turnaroundprint '\n  Avg %2d: startTime n/a - response %.2f - turnaround %.2f' % (i, float(responseSum)/numJobs,float(turnaroundSum)/numJobs)print '\n'

如果直接在终端运行,不修改print语句的话,会报这种错误:

可以打开Pycharm,把代码全部复制过去(注意选择Ctrl+Alt+Shift+V,即无格式文本粘贴,不然会出现自动换行现象),然后使用2to3命令:

 

如果没安装的uu可以安装一下

pip install 2to3

然后再Pycharm终端输入:

2to3 -w your_script.py

其中,your_script为你的新py文件名称。

新的py3文件就生成好啦!

#! /usr/bin/env python3import sys
from optparse import OptionParser
import random# finds the highest nonempty queue
# -1 if they are all empty
def FindQueue():q = hiQueuewhile q > 0:if len(queue[q]) > 0:return qq -= 1if len(queue[0]) > 0:return 0return -1def Abort(str):sys.stderr.write(str + '\n')exit(1)#
# PARSE ARGUMENTS
#parser = OptionParser()
parser.add_option('-s', '--seed', help='the random seed',default=0, action='store', type='int', dest='seed')
parser.add_option('-n', '--numQueues',help='number of queues in MLFQ (if not using -Q)',default=3, action='store', type='int', dest='numQueues')
parser.add_option('-q', '--quantum', help='length of time slice (if not using -Q)',default=10, action='store', type='int', dest='quantum')
parser.add_option('-a', '--allotment', help='length of allotment (if not using -A)',default=1, action='store', type='int', dest='allotment')
parser.add_option('-Q', '--quantumList',help='length of time slice per queue level, specified as ' + \'x,y,z,... where x is the quantum length for the highest ' + \'priority queue, y the next highest, and so forth',default='', action='store', type='string', dest='quantumList')
parser.add_option('-A', '--allotmentList',help='length of time allotment per queue level, specified as ' + \'x,y,z,... where x is the # of time slices for the highest ' + \'priority queue, y the next highest, and so forth',default='', action='store', type='string', dest='allotmentList')
parser.add_option('-j', '--numJobs', default=3, help='number of jobs in the system',action='store', type='int', dest='numJobs')
parser.add_option('-m', '--maxlen', default=100, help='max run-time of a job ' +'(if randomly generating)', action='store', type='int',dest='maxlen')
parser.add_option('-M', '--maxio', default=10,help='max I/O frequency of a job (if randomly generating)',action='store', type='int', dest='maxio')
parser.add_option('-B', '--boost', default=0,help='how often to boost the priority of all jobs back to ' +'high priority', action='store', type='int', dest='boost')
parser.add_option('-i', '--iotime', default=5,help='how long an I/O should last (fixed constant)',action='store', type='int', dest='ioTime')
parser.add_option('-S', '--stay', default=False,help='reset and stay at same priority level when issuing I/O',action='store_true', dest='stay')
parser.add_option('-I', '--iobump', default=False,help='if specified, jobs that finished I/O move immediately ' + \'to front of current queue',action='store_true', dest='iobump')
parser.add_option('-l', '--jlist', default='',help='a comma-separated list of jobs to run, in the form ' + \'x1,y1,z1:x2,y2,z2:... where x is start time, y is run ' + \'time, and z is how often the job issues an I/O request',action='store', type='string', dest='jlist')
parser.add_option('-c', help='compute answers for me', action='store_true',default=False, dest='solve')(options, args) = parser.parse_args()random.seed(options.seed)# MLFQ: How Many Queues
numQueues = options.numQueuesquantum = {}
if options.quantumList != '':# instead, extract number of queues and their time slicquantumLengths = options.quantumList.split(',')numQueues = len(quantumLengths)qc = numQueues - 1for i in range(numQueues):quantum[qc] = int(quantumLengths[i])qc -= 1
else:for i in range(numQueues):quantum[i] = int(options.quantum)allotment = {}
if options.allotmentList != '':allotmentLengths = options.allotmentList.split(',')if numQueues != len(allotmentLengths):print('number of allotments specified must match number of quantums')exit(1)qc = numQueues - 1for i in range(numQueues):allotment[qc] = int(allotmentLengths[i])if qc != 0 and allotment[qc] <= 0:print('allotment must be positive integer')exit(1)qc -= 1
else:for i in range(numQueues):allotment[i] = int(options.allotment)hiQueue = numQueues - 1# MLFQ: I/O Model
# the time for each IO: not great to have a single fixed time but...
ioTime = int(options.ioTime)# This tracks when IOs and other interrupts are complete
ioDone = {}# This stores all info about the jobs
job = {}# seed the random generator
random.seed(options.seed)# jlist 'startTime,runTime,ioFreq:startTime,runTime,ioFreq:...'
jobCnt = 0
if options.jlist != '':allJobs = options.jlist.split(':')for j in allJobs:jobInfo = j.split(',')if len(jobInfo) != 3:print('Badly formatted job string. Should be x1,y1,z1:x2,y2,z2:...')print('where x is the startTime, y is the runTime, and z is the I/O frequency.')exit(1)assert(len(jobInfo) == 3)startTime = int(jobInfo[0])runTime   = int(jobInfo[1])ioFreq    = int(jobInfo[2])job[jobCnt] = {'currPri':hiQueue, 'ticksLeft':quantum[hiQueue],'allotLeft':allotment[hiQueue], 'startTime':startTime,'runTime':runTime, 'timeLeft':runTime, 'ioFreq':ioFreq, 'doingIO':False,'firstRun':-1}if startTime not in ioDone:ioDone[startTime] = []ioDone[startTime].append((jobCnt, 'JOB BEGINS'))jobCnt += 1
else:# do something randomfor j in range(options.numJobs):startTime = 0runTime   = int(random.random() * (options.maxlen - 1) + 1)ioFreq    = int(random.random() * (options.maxio - 1) + 1)job[jobCnt] = {'currPri':hiQueue, 'ticksLeft':quantum[hiQueue],'allotLeft':allotment[hiQueue], 'startTime':startTime,'runTime':runTime, 'timeLeft':runTime, 'ioFreq':ioFreq, 'doingIO':False,'firstRun':-1}if startTime not in ioDone:ioDone[startTime] = []ioDone[startTime].append((jobCnt, 'JOB BEGINS'))jobCnt += 1numJobs = len(job)print('Here is the list of inputs:')
print('OPTIONS jobs',            numJobs)
print('OPTIONS queues',          numQueues)
for i in range(len(quantum)-1,-1,-1):print('OPTIONS allotments for queue %2d is %3d' % (i, allotment[i]))print('OPTIONS quantum length for queue %2d is %3d' % (i, quantum[i]))
print('OPTIONS boost',           options.boost)
print('OPTIONS ioTime',          options.ioTime)
print('OPTIONS stayAfterIO',     options.stay)
print('OPTIONS iobump',          options.iobump)print('\n')
print('For each job, three defining characteristics are given:')
print('  startTime : at what time does the job enter the system')
print('  runTime   : the total CPU time needed by the job to finish')
print('  ioFreq    : every ioFreq time units, the job issues an I/O')
print('              (the I/O takes ioTime units to complete)\n')print('Job List:')
for i in range(numJobs):print('  Job %2d: startTime %3d - runTime %3d - ioFreq %3d' % (i, job[i]['startTime'],job[i]['runTime'],job[i]['ioFreq']))
print('')if options.solve == False:print('Compute the execution trace for the given workloads.')print('If you would like, also compute the response and turnaround')print('times for each of the jobs.')print('')print('Use the -c flag to get the exact results when you are finished.\n')exit(0)# initialize the MLFQ queues
queue = {}
for q in range(numQueues):queue[q] = []# TIME IS CENTRAL
currTime = 0# use these to know when we're finished
totalJobs    = len(job)
finishedJobs = 0print('\nExecution Trace:\n')while finishedJobs < totalJobs:# find highest priority job# run it until either# (a) the job uses up its time quantum# (b) the job performs an I/O# check for priority boostif options.boost > 0 and currTime != 0:if currTime % options.boost == 0:print('[ time %d ] BOOST ( every %d )' % (currTime, options.boost))# remove all jobs from queues (except high queue) and put them in high queuefor q in range(numQueues-1):for j in queue[q]:if job[j]['doingIO'] == False:queue[hiQueue].append(j)queue[q] = []# change priority to high priority# reset number of ticks left for all jobs (just for lower jobs?)# add to highest run queue (if not doing I/O)for j in range(numJobs):# print '-> Boost %d (timeLeft %d)' % (j, job[j]['timeLeft'])if job[j]['timeLeft'] > 0:# print '-> FinalBoost %d (timeLeft %d)' % (j, job[j]['timeLeft'])job[j]['currPri']   = hiQueuejob[j]['ticksLeft'] = allotment[hiQueue]# print 'BOOST END: QUEUES look like:', queue# check for any I/Os doneif currTime in ioDone:for (j, type) in ioDone[currTime]:q = job[j]['currPri']job[j]['doingIO'] = Falseprint('[ time %d ] %s by JOB %d' % (currTime, type, j))if options.iobump == False or type == 'JOB BEGINS':queue[q].append(j)else:queue[q].insert(0, j)# now find the highest priority jobcurrQueue = FindQueue()if currQueue == -1:print('[ time %d ] IDLE' % (currTime))currTime += 1continue# there was at least one runnable job, and hence ...currJob = queue[currQueue][0]if job[currJob]['currPri'] != currQueue:Abort('currPri[%d] does not match currQueue[%d]' % (job[currJob]['currPri'], currQueue))job[currJob]['timeLeft']  -= 1job[currJob]['ticksLeft'] -= 1if job[currJob]['firstRun'] == -1:job[currJob]['firstRun'] = currTimerunTime   = job[currJob]['runTime']ioFreq    = job[currJob]['ioFreq']ticksLeft = job[currJob]['ticksLeft']allotLeft = job[currJob]['allotLeft']timeLeft  = job[currJob]['timeLeft']print('[ time %d ] Run JOB %d at PRIORITY %d [ TICKS %d ALLOT %d TIME %d (of %d) ]' % \(currTime, currJob, currQueue, ticksLeft, allotLeft, timeLeft, runTime))if timeLeft < 0:Abort('Error: should never have less than 0 time left to run')# UPDATE TIMEcurrTime += 1# CHECK FOR JOB ENDINGif timeLeft == 0:print('[ time %d ] FINISHED JOB %d' % (currTime, currJob))finishedJobs += 1job[currJob]['endTime'] = currTime# print 'BEFORE POP', queuedone = queue[currQueue].pop(0)# print 'AFTER POP', queueassert(done == currJob)continue# CHECK FOR IOissuedIO = Falseif ioFreq > 0 and (((runTime - timeLeft) % ioFreq) == 0):# time for an IO!print('[ time %d ] IO_START by JOB %d' % (currTime, currJob))issuedIO = Truedesched = queue[currQueue].pop(0)assert(desched == currJob)job[currJob]['doingIO'] = True# this does the bad rule -- reset your tick counter if you stay at the same levelif options.stay == True:job[currJob]['ticksLeft'] = quantum[currQueue]job[currJob]['allotLeft'] = allotment[currQueue]# add to IO Queue: but which queue?futureTime = currTime + ioTimeif futureTime not in ioDone:ioDone[futureTime] = []print('IO DONE')ioDone[futureTime].append((currJob, 'IO_DONE'))# CHECK FOR QUANTUM ENDING AT THIS LEVEL (BUT REMEMBER, THERE STILL MAY BE ALLOTMENT LEFT)if ticksLeft == 0:if issuedIO == False:# IO HAS NOT BEEN ISSUED (therefor pop from queue)'desched = queue[currQueue].pop(0)assert(desched == currJob)job[currJob]['allotLeft'] = job[currJob]['allotLeft'] - 1if job[currJob]['allotLeft'] == 0:# this job is DONE at this level, so move onif currQueue > 0:# in this case, have to change the priority of the jobjob[currJob]['currPri']   = currQueue - 1job[currJob]['ticksLeft'] = quantum[currQueue-1]job[currJob]['allotLeft'] = allotment[currQueue-1]if issuedIO == False:queue[currQueue-1].append(currJob)else:job[currJob]['ticksLeft'] = quantum[currQueue]job[currJob]['allotLeft'] = allotment[currQueue]if issuedIO == False:queue[currQueue].append(currJob)else:# this job has more time at this level, so just push it to endjob[currJob]['ticksLeft'] = quantum[currQueue]if issuedIO == False:queue[currQueue].append(currJob)# print out statistics
print('')
print('Final statistics:')
responseSum   = 0
turnaroundSum = 0
for i in range(numJobs):response   = job[i]['firstRun'] - job[i]['startTime']turnaround = job[i]['endTime'] - job[i]['startTime']print('  Job %2d: startTime %3d - response %3d - turnaround %3d' % (i, job[i]['startTime'],response, turnaround))responseSum   += responseturnaroundSum += turnaroundprint('\n  Avg %2d: startTime n/a - response %.2f - turnaround %.2f' % (i,float(responseSum)/numJobs,float(turnaroundSum)/numJobs))print('\n')

这篇关于操作系统导论-py2文件修改为py3文件快捷解决方法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/855754

相关文章

【C++】_list常用方法解析及模拟实现

相信自己的力量,只要对自己始终保持信心,尽自己最大努力去完成任何事,就算事情最终结果是失败了,努力了也不留遗憾。💓💓💓 目录   ✨说在前面 🍋知识点一:什么是list? •🌰1.list的定义 •🌰2.list的基本特性 •🌰3.常用接口介绍 🍋知识点二:list常用接口 •🌰1.默认成员函数 🔥构造函数(⭐) 🔥析构函数 •🌰2.list对象

如何解决线上平台抽佣高 线下门店客流少的痛点!

目前,许多传统零售店铺正遭遇客源下降的难题。尽管广告推广能带来一定的客流,但其费用昂贵。鉴于此,众多零售商纷纷选择加入像美团、饿了么和抖音这样的大型在线平台,但这些平台的高佣金率导致了利润的大幅缩水。在这样的市场环境下,商家之间的合作网络逐渐成为一种有效的解决方案,通过资源和客户基础的共享,实现共同的利益增长。 以最近在上海兴起的一个跨行业合作平台为例,该平台融合了环保消费积分系统,在短

浅谈主机加固,六种有效的主机加固方法

在数字化时代,数据的价值不言而喻,但随之而来的安全威胁也日益严峻。从勒索病毒到内部泄露,企业的数据安全面临着前所未有的挑战。为了应对这些挑战,一种全新的主机加固解决方案应运而生。 MCK主机加固解决方案,采用先进的安全容器中间件技术,构建起一套内核级的纵深立体防护体系。这一体系突破了传统安全防护的局限,即使在管理员权限被恶意利用的情况下,也能确保服务器的安全稳定运行。 普适主机加固措施:

webm怎么转换成mp4?这几种方法超多人在用!

webm怎么转换成mp4?WebM作为一种新兴的视频编码格式,近年来逐渐进入大众视野,其背后承载着诸多优势,但同时也伴随着不容忽视的局限性,首要挑战在于其兼容性边界,尽管WebM已广泛适应于众多网站与软件平台,但在特定应用环境或老旧设备上,其兼容难题依旧凸显,为用户体验带来不便,再者,WebM格式的非普适性也体现在编辑流程上,由于它并非行业内的通用标准,编辑过程中可能会遭遇格式不兼容的障碍,导致操

透彻!驯服大型语言模型(LLMs)的五种方法,及具体方法选择思路

引言 随着时间的发展,大型语言模型不再停留在演示阶段而是逐步面向生产系统的应用,随着人们期望的不断增加,目标也发生了巨大的变化。在短短的几个月的时间里,人们对大模型的认识已经从对其zero-shot能力感到惊讶,转变为考虑改进模型质量、提高模型可用性。 「大语言模型(LLMs)其实就是利用高容量的模型架构(例如Transformer)对海量的、多种多样的数据分布进行建模得到,它包含了大量的先验

【北交大信息所AI-Max2】使用方法

BJTU信息所集群AI_MAX2使用方法 使用的前提是预约到相应的算力卡,拥有登录权限的账号密码,一般为导师组共用一个。 有浏览器、ssh工具就可以。 1.新建集群Terminal 浏览器登陆10.126.62.75 (如果是1集群把75改成66) 交互式开发 执行器选Terminal 密码随便设一个(需记住) 工作空间:私有数据、全部文件 加速器选GeForce_RTX_2080_Ti

pip-tools:打造可重复、可控的 Python 开发环境,解决依赖关系,让代码更稳定

在 Python 开发中,管理依赖关系是一项繁琐且容易出错的任务。手动更新依赖版本、处理冲突、确保一致性等等,都可能让开发者感到头疼。而 pip-tools 为开发者提供了一套稳定可靠的解决方案。 什么是 pip-tools? pip-tools 是一组命令行工具,旨在简化 Python 依赖关系的管理,确保项目环境的稳定性和可重复性。它主要包含两个核心工具:pip-compile 和 pip

【VUE】跨域问题的概念,以及解决方法。

目录 1.跨域概念 2.解决方法 2.1 配置网络请求代理 2.2 使用@CrossOrigin 注解 2.3 通过配置文件实现跨域 2.4 添加 CorsWebFilter 来解决跨域问题 1.跨域概念 跨域问题是由于浏览器实施了同源策略,该策略要求请求的域名、协议和端口必须与提供资源的服务相同。如果不相同,则需要服务器显式地允许这种跨域请求。一般在springbo

AI(文生语音)-TTS 技术线路探索学习:从拼接式参数化方法到Tacotron端到端输出

AI(文生语音)-TTS 技术线路探索学习:从拼接式参数化方法到Tacotron端到端输出 在数字化时代,文本到语音(Text-to-Speech, TTS)技术已成为人机交互的关键桥梁,无论是为视障人士提供辅助阅读,还是为智能助手注入声音的灵魂,TTS 技术都扮演着至关重要的角色。从最初的拼接式方法到参数化技术,再到现今的深度学习解决方案,TTS 技术经历了一段长足的进步。这篇文章将带您穿越时

Linux操作系统 初识

在认识操作系统之前,我们首先来了解一下计算机的发展: 计算机的发展 世界上第一台计算机名叫埃尼阿克,诞生在1945年2月14日,用于军事用途。 后来因为计算机的优势和潜力巨大,计算机开始飞速发展,并产生了一个当时一直有效的定律:摩尔定律--当价格不变时,集成电路上可容纳的元器件的数目,约每隔18-24个月便会增加一倍,性能也将提升一倍。 那么相应的,计算机就会变得越来越快,越来越小型化。