我已经开始使用Visual Studio代码进行远程调试,但是无法正常工作。远程和本地开发PC均运行ptvsd的4.1.3版本。远程计算机具有脚本:
import ptvsd
ptvsd.enable_attach()
#Enable the below line of code only if you want the application to wait untill the debugger has att$
#ptvsd.wait_for_attach()
import random
guesses_made = 0
name = input('Hello! What is your name?\n')
number = random.randint(1, 20)
print('Well, {0}, I am thinking of a number between 1 and 20.'.format(name))
while guesses_made < 6:
guess = int(input('Take a guess: '))
guesses_made += 1
if guess < number:
print('Your guess is too low.')
if guess > number:
print('Your guess is too high.')
if guess == number:
break
if guess == number:
print('Good job, {0}! You guessed my number in {1} guesses!'.format(name, guesses_made))
else:
print('Nope. The number I was thinking of was {0}'.format(number))
本地计算机是:
import ptvsd
ptvsd.enable_attach(address = ('192.34.98.197',3000))
#Enable the below line of code only if you want the application to wait untill the debugger has attached to it
#ptvsd.wait_for_attach()
import random
guesses_made = 0
name = input('Hello! What is your name?\n')
number = random.randint(1, 20)
print('Well, {0}, I am thinking of a number between 1 and 20.'.format(name))
while guesses_made < 6:
guess = int(input('Take a guess: '))
guesses_made += 1
if guess < number:
print('Your guess is too low.')
if guess > number:
print('Your guess is too high.')
if guess == number:
break
if guess == number:
print('Good job, {0}! You guessed my number in {1} guesses!'.format(name, guesses_made))
else:
print('Nope. The number I was thinking of was {0}'.format(number))
我已将条目添加到launch.json中:
{
"name": "Attach (Remote Debug)",
"type": "python",
"request": "attach",
"localRoot": "${workspaceRoot}",
"remoteRoot": "/home/pi/testdebug/",
"port": 3000,
"secret": "my_secret",
"host":"localhost"
},
这是我收到的错误:
> PS C:\IOT\Github\RaspberryPi\test_remote_debug> python
> .\test_remote_debug.py Traceback (most recent call last): File
> ".\test_remote_debug.py", line 2, in <module>
> ptvsd.enable_attach(address = ('192.34.98.197',3000)) File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\attach_server.py", line 72,
> in enable_attach
> redirect_output=redirect_output, File "C:\Program Files (x86)\Python37-32\lib\site-packages\ptvsd\_remote.py", line 85, in
> enable_attach
> suspend=False) File "C:\Program Files (x86)\Python37-32\lib\site-packages\ptvsd\_vendored\pydevd\pydevd.py",
> line 1313, in settrace
> stop_at_frame, File "C:\Program Files (x86)\Python37-32\lib\site-packages\ptvsd\_vendored\pydevd\pydevd.py",
> line 1362, in _locked_settrace
> debugger.connect(host, port) # Note: connect can raise error. File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\_vendored\pydevd\pydevd.py",
> line 355, in connect
> s = start_client(host, port) File "C:\Program Files (x86)\Python37-32\lib\site-packages\ptvsd\pydevd_hooks.py", line 85,
> in <lambda>
> _start_client = (lambda h, p: start_client(daemon, h, p)) File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\_remote.py", line 72, in
> <lambda>
> start_client=(lambda daemon, h, port: start_daemon()), File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\_remote.py", line 64, in
> start_daemon
> _, next_session = daemon.start_server(addr=(host, port)) File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\daemon.py", line 157, in
> start_server
> self._server = create_server(addr.host, addr.port) File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\socket.py", line 77, in
> create_server
> server.bind((host, port)) OSError: [WinError 10049] The requested address is not valid in its context PS
> C:\IOT\Github\RaspberryPi\test_remote_debug> python
> .\test_remote_debug.py Traceback (most recent call last): File
> ".\test_remote_debug.py", line 2, in <module>
> ptvsd.enable_attach(address = ('192.34.98.197',3000)) File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\attach_server.py", line 72,
> in enable_attach
> redirect_output=redirect_output, File "C:\Program Files (x86)\Python37-32\lib\site-packages\ptvsd\_remote.py", line 85, in
> enable_attach
> suspend=False) File "C:\Program Files (x86)\Python37-32\lib\site-packages\ptvsd\_vendored\pydevd\pydevd.py",
> line 1313, in settrace
> stop_at_frame, File "C:\Program Files (x86)\Python37-32\lib\site-packages\ptvsd\_vendored\pydevd\pydevd.py",
> line 1362, in _locked_settrace
> debugger.connect(host, port) # Note: connect can raise error. File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\_vendored\pydevd\pydevd.py",
> line 355, in connect
> s = start_client(host, port) File "C:\Program Files (x86)\Python37-32\lib\site-packages\ptvsd\pydevd_hooks.py", line 85,
> in <lambda>
> _start_client = (lambda h, p: start_client(daemon, h, p)) File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\_remote.py", line 72, in
> <lambda>
> start_client=(lambda daemon, h, port: start_daemon()), File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\_remote.py", line 64, in
> start_daemon
> _, next_session = daemon.start_server(addr=(host, port)) File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\daemon.py", line 157, in
> start_server
> self._server = create_server(addr.host, addr.port) File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\socket.py", line 77, in
> create_server
> server.bind((host, port)) OSError: [WinError 10049] The requested address is not valid in its context
如果有人对如何解决此问题有任何想法,请告诉我。
答案 0 :(得分:1)
您的num_rounds = 100
dice_wins = {tuple(x):0 for x in dices}
for dice1, dice2 in it.combinations(dices, 2):
for _ in range(num_rounds):
dice1_result = dice1[randint(0, 5)]
dice2_result = dice2[randint(0, 5)]
if dice1_result > dice2_result:
dice_wins[tuple(dice1)] += 1
elif dice2_result > dice1_result:
dice_wins[tuple(dice2)] += 1
max_win = max(list(dice_wins.values()))
die_with_max_win = [dice for dice in dices if dice_wins[tuple(dice)] == max_win]
if len(die_with_max_win) == 1:
return die_with_max_win[0] # only dice with that many wins
else:
return -1 # more than one dice with max wins
已过时,因为它是为旧调试器配置的。有关最新的说明,请参见https://code.visualstudio.com/docs/python/debugging#_remote-debugging(例如launch.json
和localRoot
应该在remoteRoote
下)。