本文整理汇总了Python中session.Session.start方法的典型用法代码示例。如果您正苦于以下问题:Python Session.start方法的具体用法?Python Session.start怎么用?Python Session.start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类session.Session
的用法示例。
在下文中一共展示了Session.start方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AppDelegate
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import start [as 别名]
class AppDelegate(NSObject):
def applicationDidFinishLaunching_(self, app):
self.session = None
self.init_status_bar()
self.init_menu()
def init_status_bar(self):
self.status_bar = NSStatusBar.systemStatusBar()
self.status_item = self.status_bar.statusItemWithLength_(NSVariableStatusItemLength)
self.status_item.setHighlightMode_(1)
icon = NSImage.alloc().initWithContentsOfFile_('icon.png')
self.status_item.setImage_(icon)
def init_menu(self):
self.menu = NSMenu.alloc().init()
self.menu_item_start = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Start', 'start:', '')
self.menu.addItem_(self.menu_item_start)
menu_item_quit = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_('Quit', 'terminate:', '')
self.menu.addItem_(menu_item_quit)
self.status_item.setMenu_(self.menu)
def start_(self, notification):
if self.session != None:
self.session.stop()
self.session = Session()
self.session.start()
示例2: prepSimProfile
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import start [as 别名]
def prepSimProfile(self):
"""
Prepare data and create User Sessions (to be simulated).
each of them will wait for the start signal.
"""
# @todo: implement a mechanism to load and use other types of RAS (from ras_type.py)
self.__ras_obj = MikrotikRas(self.__sim_profile.nas_id,
self.__sim_profile.nas_ip,
self.__sim_profile.radius_secret,
self.__sim_profile.aaa_server_ip)
# @todo: we better save and keep track of the used IP
ips = []
for ip in IPy.IP( self.__sim_profile.user_ips ):
if str(ip).endswith("0") or "255" in str(ip):
continue
ips.append( str(ip) )
for i in xrange( self.__sim_profile.total_sessions ):
session_type = random.choice( self.__sim_profile.session_types )
self.__start_sessions[ session_type ] = 1 + self.__start_sessions.get(session_type, 0)
username, password = self.__genUserPass(i)
sess = Session(session_type, self.__ready_event,
username, password,
ips.pop(0), self.__ras_obj)
sess.start()
self.__sessions.append(sess)
示例3: SocketHandler
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import start [as 别名]
class SocketHandler(tornado.websocket.WebSocketHandler):
def open(self):
logging.info("Connected: websocket")
self.device = 'web'
self.session = Session(self, world)
self.session.start()
def on_message(self, message):
dispatch(self.session, message.strip())
示例4: MudTelnetProtocol
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import start [as 别名]
class MudTelnetProtocol(StatefulTelnetProtocol):
def connectionMade(self):
logging.info("Connected: telnet")
self.device = 'telnet'
self.session = Session(self, world)
self.session.start()
def lineReceived(self, line):
logging.debug("DEBUG: lineReceived called with %s" % line)
dispatch(self.session, line.strip())
def write_message(self, message):
self.transport.write(str(message))
self.clearLineBuffer()
def connectionLost(self, reason):
logging.debug("DEBUG: called connectionLost with: %s" % str(reason))
示例5: fake_session
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import start [as 别名]
def fake_session():
session = Session()
screenshots = load_all_screenshots( Paths.shots_dir )
screenshots.sort( key=operator.attrgetter('time') )
session_shots = screenshots[-100:]
start_time = session_shots[0].time-1
end_time = session_shots[-1].time+1
session.start = start_time
session.end = end_time
api.create_session( session )
api.start_session( session )
map( upload_shot, session_shots )
api.end_session( session )
示例6: test
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import start [as 别名]
def test(self, params):
print('\n%s: testing...' %datetime.now())
sys.stdout.flush()
session = Session(self._graph, self.results_dir, params['model_name'])
if 'init_step' not in params or params['init_step'] is None:
init_step = session.init_step
else:
init_step = params['init_step']
if 'step_num' not in params or params['step_num'] is None:
step_num = int(np.ceil(np.float(self.fold_size) / self._batch_size))
else:
step_num = params['step_num']
results_file_name = Tester.RESULTS_FILE + '-' + str(init_step) + '-' + \
self.fold_name + '-' + str(step_num) + '.json'
results_file = os.path.join(self.results_dir, results_file_name)
if not params['load_results'] or not os.path.isfile(results_file):
session.init(self._classifier, init_step, params['restoring_file'])
session.start()
if init_step == 0:
print 'WARNING: testing an untrained model'
total_step_num = step_num * params['epoch_num']
test_num = total_step_num * self._batch_size
print('%s: test_num=%d' % (datetime.now(), step_num * self._batch_size))
print('%s: epoch_num=%d' % (datetime.now(), params['epoch_num']))
results = {}
results['losses'] = np.zeros(test_num, dtype=np.float32)
results['probs'] = np.zeros((test_num, Reader.CLASSES_NUM), dtype=np.float32)
results['labels'] = np.zeros(test_num, dtype=np.int64)
start_time = time.time()
for step in range(total_step_num):
#print('%s: eval_iter=%d' %(datetime.now(), i))
loss_batch, prob_batch, label_batch = session.run(
[self._cross_entropy_losses, self._probs, self._input['labels']]
)
begin = step * self._batch_size
results['losses'][begin:begin+self._batch_size] = loss_batch
results['probs'][begin:begin+self._batch_size, :] = prob_batch
results['labels'][begin:begin + self._batch_size] = label_batch
if (step+1) % step_num == 0:
print "Epoch num: %d" % ((step+1)/step_num)
if session.should_stop():
break
duration = time.time() - start_time
print('%s: duration = %.1f sec' %(datetime.now(), float(duration)))
sys.stdout.flush()
if self.writer is not None:
summary_str = session.run(self._all_summaries)
self.writer.write_summaries(summary_str, init_step)
session.stop()
else:
print 'WARNING: using precomputed results'
results = utils.load_from_file(results_file)
results['loss'] = np.mean(results['losses']).item()
results = self.get_all_stats(results)
if self.writer is not None and not params['load_results']:
self.writer.write_scalars({'losses/testing/cross_entropy_loss': results['loss'],
'accuracy': results['accuracy']}, init_step)
utils.dump_to_file(results, results_file)
return init_step, results['loss']
示例7: ArgumentParser
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import start [as 别名]
import subprocess
from logger import logger
parser = ArgumentParser()
parser.add_argument("sessiondir")
Server.add_parser_arguments(parser)
Orchestra.add_parser_arguments(parser)
options = parser.parse_args()
if options.realtime:
if options.max_passivity:
raise Exception("cannot enforce max passivity in real time")
session = Session(realtime=True)
sessiondir = session.dir
logfile = session.get_log_reader()
session.start()
else:
sessiondir = options.sessiondir
logfilename = "%s/session.log" % sessiondir
print "session: %s" % sessiondir
tr_log = TrLogReader(logfilename, options.torrentname,
realtime=options.realtime,
pretend_sequential=options.pretend_sequential).get_log()
tr_log.ignore_non_downloaded_files()
server = Server(options)
orchestra = Orchestra(sessiondir, tr_log, options)
server.set_orchestra(orchestra)