Как делает поточную обработку. Остальная часть урожая потока его кванта в Python?

Простой блок switch () поможет вам в этом. Основываясь на количестве выбранных опций, вы можете создать строку, готовую для отображения.

function getFixedAgentValues(select) {
  var retString = "";
  var result = [];
  var options = select && select.options;
  var opt;

  for (var i = 0, iLen = options.length; i < iLen; i++) {
    opt = options[i];
    if (opt.selected) {
      result.push(opt.value || opt.text);
    }
  }
  switch (result.length) {
    case 1:
      retString = result[0];
      break;
    case 2:
      retString = result[0] + " and " +
        result[1];
      break;
    case 3:
      retString = result[0] + ", " +
        result[1] + " and " + result[2];
      break;
    case 4:
      retString = result[0] + ", " +
        result[1] + ", " + result[2] + " and " + result[3];
      break;
  }
  return retString;
}


function myFixAgentList1() {
  var a = document.getElementById("FixAgent");
document.getElementById("FixAgentListArray1").innerHTML=getFixedAgentValues(a);
}

и слегка модифицированный HTML

<select multiple id="FixAgent" onChange="myFixAgentList1();">
41
задан Tom Future 24 April 2009 в 22:29
поделиться

3 ответа

time.sleep (0) достаточно для контроля урожайности - нет необходимости использовать положительный эпсилон. Действительно, time.sleep (0) Означает «уступить любому другому потоку, который может быть готов».

68
ответ дан 27 November 2019 в 00:30
поделиться

Read up on the Global Interpreter Lock (GIL).

For example: http://jessenoller.com/2009/02/01/python-threads-and-the-global-interpreter-lock/

Also: http://www.pyzine.com/Issue001/Section_Articles/article_ThreadingGlobalInterpreter.html

Do this in your code if you must do Busy Waiting (e.g. polling a device).

time.sleep( 0.0001 )

This will yield to the thread scheduler.

Also, I collected some notes and references in http://homepage.mac.com/s_lott/iblog/architecture/C551260341/E20081031204203/index.html

13
ответ дан 27 November 2019 в 00:30
поделиться

If you're doing this on *nix, you might find the select library useful. Kamaela also has a few components you may find useful, but it may require a bit of a paradigm change.

4
ответ дан 27 November 2019 в 00:30
поделиться
Другие вопросы по тегам:

Похожие вопросы: