{"action":"created","issue":{"url":"https://api.github.com/repos/thiezn/iperf3-python/issues/29","repository_url":"https://api.github.com/repos/thiezn/iperf3-python","labels_url":"https://api.github.com/repos/thiezn/iperf3-python/issues/29/labels{/name}","comments_url":"https://api.github.com/repos/thiezn/iperf3-python/issues/29/comments","events_url":"https://api.github.com/repos/thiezn/iperf3-python/issues/29/events","html_url":"https://github.com/thiezn/iperf3-python/issues/29","id":303640096,"number":29,"title":"Raise exception when port given to server is already occupied","user":{"login":"adamkpickering","id":19395776,"avatar_url":"https://avatars0.githubusercontent.com/u/19395776?v=4","gravatar_id":"","url":"https://api.github.com/users/adamkpickering","html_url":"https://github.com/adamkpickering","followers_url":"https://api.github.com/users/adamkpickering/followers","following_url":"https://api.github.com/users/adamkpickering/following{/other_user}","gists_url":"https://api.github.com/users/adamkpickering/gists{/gist_id}","starred_url":"https://api.github.com/users/adamkpickering/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamkpickering/subscriptions","organizations_url":"https://api.github.com/users/adamkpickering/orgs","repos_url":"https://api.github.com/users/adamkpickering/repos","events_url":"https://api.github.com/users/adamkpickering/events{/privacy}","received_events_url":"https://api.github.com/users/adamkpickering/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-03-08T21:33:48Z","updated_at":"2018-03-12T15:17:39Z","closed_at":null,"author_association":"NONE","body":"I am trying to implement an iperf3 server that is capable of doing multiple simultaneous tests. I am planning on doing the handling of multiple tests using Twisted. Unfortunately I've run into an issue with finding a port to give the iperf3.Server: if I give it a port that is already being used by another process, no error information is returned until the call to Server.run() returns. Until this point there is no way of telling if the port was good or not.\r\n\r\nIt seems to me that the pythonic way to do this would be to define an exception (\"PortTakenError\" or something similar) that is raised _before_ the call to Server.run() returns. That way, people can encapsulate the Server.run() call in a try-except statement and handle a \"PortTakenError\" gracefully.\r\n\r\nIs this doable? I can probably figure out how to implement this; if I submit a pull request with these changes would you accept it?"},"comment":{"url":"https://api.github.com/repos/thiezn/iperf3-python/issues/comments/372346390","html_url":"https://github.com/thiezn/iperf3-python/issues/29#issuecomment-372346390","issue_url":"https://api.github.com/repos/thiezn/iperf3-python/issues/29","id":372346390,"user":{"login":"thiezn","id":7849566,"avatar_url":"https://avatars1.githubusercontent.com/u/7849566?v=4","gravatar_id":"","url":"https://api.github.com/users/thiezn","html_url":"https://github.com/thiezn","followers_url":"https://api.github.com/users/thiezn/followers","following_url":"https://api.github.com/users/thiezn/following{/other_user}","gists_url":"https://api.github.com/users/thiezn/gists{/gist_id}","starred_url":"https://api.github.com/users/thiezn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thiezn/subscriptions","organizations_url":"https://api.github.com/users/thiezn/orgs","repos_url":"https://api.github.com/users/thiezn/repos","events_url":"https://api.github.com/users/thiezn/events{/privacy}","received_events_url":"https://api.github.com/users/thiezn/received_events","type":"User","site_admin":false},"created_at":"2018-03-12T15:17:39Z","updated_at":"2018-03-12T15:17:39Z","author_association":"OWNER","body":"Hi @adamkpickering \r\n\r\nI see what you mean, there is indeed no exception raised but rather an error provided in the TestResult. I've quickly created a new branch https://github.com/thiezn/iperf3-python/commit/7ae5a6a0deac97d0935b8398b75d09dc3f0ea74a to see if it makes sense to raise an exception when an error occurs. Have a look at the branch to see if this is something usable for you. I would have to see if there's a sensible standard exception or create a new one.\r\n\r\nHere's the output you get when a port is already taken:\r\n```python\r\n>>> import iperf3\r\n>>> server = iperf3.Server()\r\n>>> server.port = 3306\r\n>>> server.run()\r\nTraceback (most recent call last):\r\n  File \"<stdin>\", line 1, in <module>\r\n  File \"development/iperf3-python/iperf3/iperf3.py\", line 680, in run\r\n    return TestResult(data_queue.get())\r\n  File \"development/iperf3-python/iperf3/iperf3.py\", line 767, in __init__\r\n    raise IOError(self.json['error'])\r\nOSError: unable to start listener for connections:\r\n```"}}
{"actor":{"display_login":"thiezn"}}