{"action":"created","comment":{"url":"https://api.github.com/repos/kaustubh-karkare/project-omega/pulls/comments/108970720","pull_request_review_id":30039838,"id":108970720,"diff_hunk":"@@ -0,0 +1,119 @@\n+import socket\n+import sys\n+import logging\n+import argparse\n+import threading\n+import time\n+from urlparse import urlparse\n+from mimetools import Message\n+from StringIO import StringIO\n+import os\n+LEVELS = {'DEBUG': logging.DEBUG,\n+          'INFO': logging.INFO,\n+          'WARNING': logging.WARNING,\n+          'ERROR': logging.ERROR,\n+          'CRITICAL': logging.CRITICAL}\n+THREAD_COUNT = 4\n+\n+class Client (threading.Thread):\n+    def __init__(self, thread_id, hostname, \n+    \t\t\t port, path, start_range, end_range):\n+        threading.Thread.__init__(self)\n+        self.thread_id = thread_id\n+        self.hostname = hostname\n+        self.port = port\n+        self.path = path\n+        self.start_range = start_range\n+        self.end_range = end_range\n+\n+    def run(self):\n+\t\tlogging.info(\"[Start: %s]\", self.start_range)\n+\t\tlogging.info(\"[End: %s]\", self.end_range)\n+\t\tsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n+\t\ttry:\n+\t\t\tsock.connect((self.hostname, self.port))\n+\t\texcept socket.error, msg:\n+\t\t\tsys.stderr.write(\"[ERROR] %s\\n\" % msg[1])\n+\t\t\tsys.exit(1)\n+\t\t# Send HEAD Request to fetch Headers  \n+\t\tsock.send(\"GET %s HTTP/1.1\\r\\nHost: %s\\r\\nRange: bytes=%s-%s\\r\\nConnection: close\\r\\n\\r\\n\"\n+\t\t\t% (self.path, self.hostname, self.start_range, self.end_range))\n+\t\tdata = sock.recv(512)\n+\t\trecv = \"\"\n+\t\twhile len(data):\n+\t\t\trecv = recv + data\n+\t\t\tdata = sock.recv(512)\n+\t\t# Write to Partfile after removing Headers\n+\t\twith open('partfile'+str(self.thread_id),'w') as f:\n+\t\t\tf.write(\"\".join(recv.split(\"\\r\\n\\r\\n\")[1:]))\n+\t\tsock.close()\n+\n+\n+\n+\"\"\" GET contents from a URL in multiple threads. \n+Accepts URL as command line argument. \n+\"\"\"\n+def get(url):\n+\turl = urlparse(url)\n+\tHOSTNAME = url.hostname\n+\tPORT = url.port or 80\n+\tPATH = url.path\n+\tlogging.info(\"[Host: %s Port: %s Path: %s]\", HOSTNAME, PORT, PATH)\n+\tsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n+\ttry:\n+\t\tsock.connect((HOSTNAME, PORT))\n+\texcept socket.error, msg:\n+\t\tsys.stderr.write(\"[ERROR] %s\\n\" % msg[1])\n+\t\tsys.exit(1)\n+\t# Send HEAD Request to fetch Headers \n+\tsock.send(\"HEAD %s HTTP/1.0\\r\\nHost: %s\\r\\n\\r\\n\" % (PATH, HOSTNAME))\n+\tdata = sock.recv(1024)\n+\trecv = \"\"\n+\twhile len(data):\n+\t\trecv = recv + data\n+\t\tdata = sock.recv(1024)\n+\tsock.close()\n+\t# Parse Headers using MIMETools to Fetch Content-Length\n+\trequest_line, headers_alone = recv.split('\\r\\n', 1)\n+\theaders = Message(StringIO(headers_alone))\n+\tcontent_length = headers['content-length']\n+\tlogging.info(\"[Content-Length: %s]\",content_length)\n+\t# initialize threads for download\n+\tthread_count = THREAD_COUNT;\n+\tbytes_per_thread = int(content_length)/thread_count;\n+\tclients = []\n+\tfor x in xrange(0,thread_count):\n+\t\tstart_range = (x)*bytes_per_thread\n+\t\tif x is not 0:\n+\t\t\tstart_range += 1\n+\t\tend_range = (x+1)*bytes_per_thread\n+\t\tif x == (thread_count-1):\n+\t\t\tend_range = int(content_length) - 1\n+\t\tclient = Client(x,HOSTNAME,PORT,PATH,start_range,end_range)\n+\t\tclients.append(client)\n+\tfor x in xrange(0,thread_count):\n+\t\tclients[x].start()\n+\twhile threading.active_count() > 1:\n+\t\ttime.sleep(1)","path":"solutions/koushik/assignment-2/assignment-2.2.py","position":97,"original_position":97,"commit_id":"c739287e80637c3b0af5b4d8608ba4e550e5d92f","original_commit_id":"c739287e80637c3b0af5b4d8608ba4e550e5d92f","user":{"login":"kaustubh-karkare","id":1102450,"avatar_url":"https://avatars3.githubusercontent.com/u/1102450?v=3","gravatar_id":"","url":"https://api.github.com/users/kaustubh-karkare","html_url":"https://github.com/kaustubh-karkare","followers_url":"https://api.github.com/users/kaustubh-karkare/followers","following_url":"https://api.github.com/users/kaustubh-karkare/following{/other_user}","gists_url":"https://api.github.com/users/kaustubh-karkare/gists{/gist_id}","starred_url":"https://api.github.com/users/kaustubh-karkare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaustubh-karkare/subscriptions","organizations_url":"https://api.github.com/users/kaustubh-karkare/orgs","repos_url":"https://api.github.com/users/kaustubh-karkare/repos","events_url":"https://api.github.com/users/kaustubh-karkare/events{/privacy}","received_events_url":"https://api.github.com/users/kaustubh-karkare/received_events","type":"User","site_admin":false},"body":"Isn't this equivalant to thread.join()?","created_at":"2017-03-30T16:15:11Z","updated_at":"2017-03-30T16:16:53Z","html_url":"https://github.com/kaustubh-karkare/project-omega/pull/6#discussion_r108970720","pull_request_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/pulls/6","_links":{"self":{"href":"https://api.github.com/repos/kaustubh-karkare/project-omega/pulls/comments/108970720"},"html":{"href":"https://github.com/kaustubh-karkare/project-omega/pull/6#discussion_r108970720"},"pull_request":{"href":"https://api.github.com/repos/kaustubh-karkare/project-omega/pulls/6"}}},"pull_request":{"url":"https://api.github.com/repos/kaustubh-karkare/project-omega/pulls/6","id":110471540,"html_url":"https://github.com/kaustubh-karkare/project-omega/pull/6","diff_url":"https://github.com/kaustubh-karkare/project-omega/pull/6.diff","patch_url":"https://github.com/kaustubh-karkare/project-omega/pull/6.patch","issue_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/issues/6","number":6,"state":"open","locked":false,"title":"Assignment 1.2","user":{"login":"koushikmln","id":8670988,"avatar_url":"https://avatars0.githubusercontent.com/u/8670988?v=3","gravatar_id":"","url":"https://api.github.com/users/koushikmln","html_url":"https://github.com/koushikmln","followers_url":"https://api.github.com/users/koushikmln/followers","following_url":"https://api.github.com/users/koushikmln/following{/other_user}","gists_url":"https://api.github.com/users/koushikmln/gists{/gist_id}","starred_url":"https://api.github.com/users/koushikmln/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/koushikmln/subscriptions","organizations_url":"https://api.github.com/users/koushikmln/orgs","repos_url":"https://api.github.com/users/koushikmln/repos","events_url":"https://api.github.com/users/koushikmln/events{/privacy}","received_events_url":"https://api.github.com/users/koushikmln/received_events","type":"User","site_admin":false},"body":"","created_at":"2017-03-13T18:43:04Z","updated_at":"2017-03-30T16:16:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e6e30c3c42372962200463202081583aa4a62c43","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/pulls/6/commits","review_comments_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/pulls/6/comments","review_comment_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/pulls/comments{/number}","comments_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/issues/6/comments","statuses_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/statuses/c739287e80637c3b0af5b4d8608ba4e550e5d92f","head":{"label":"koushikmln:master","ref":"master","sha":"c739287e80637c3b0af5b4d8608ba4e550e5d92f","user":{"login":"koushikmln","id":8670988,"avatar_url":"https://avatars0.githubusercontent.com/u/8670988?v=3","gravatar_id":"","url":"https://api.github.com/users/koushikmln","html_url":"https://github.com/koushikmln","followers_url":"https://api.github.com/users/koushikmln/followers","following_url":"https://api.github.com/users/koushikmln/following{/other_user}","gists_url":"https://api.github.com/users/koushikmln/gists{/gist_id}","starred_url":"https://api.github.com/users/koushikmln/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/koushikmln/subscriptions","organizations_url":"https://api.github.com/users/koushikmln/orgs","repos_url":"https://api.github.com/users/koushikmln/repos","events_url":"https://api.github.com/users/koushikmln/events{/privacy}","received_events_url":"https://api.github.com/users/koushikmln/received_events","type":"User","site_admin":false},"repo":{"id":84724809,"name":"project-omega","full_name":"koushikmln/project-omega","owner":{"login":"koushikmln","id":8670988,"avatar_url":"https://avatars0.githubusercontent.com/u/8670988?v=3","gravatar_id":"","url":"https://api.github.com/users/koushikmln","html_url":"https://github.com/koushikmln","followers_url":"https://api.github.com/users/koushikmln/followers","following_url":"https://api.github.com/users/koushikmln/following{/other_user}","gists_url":"https://api.github.com/users/koushikmln/gists{/gist_id}","starred_url":"https://api.github.com/users/koushikmln/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/koushikmln/subscriptions","organizations_url":"https://api.github.com/users/koushikmln/orgs","repos_url":"https://api.github.com/users/koushikmln/repos","events_url":"https://api.github.com/users/koushikmln/events{/privacy}","received_events_url":"https://api.github.com/users/koushikmln/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/koushikmln/project-omega","description":null,"fork":true,"url":"https://api.github.com/repos/koushikmln/project-omega","forks_url":"https://api.github.com/repos/koushikmln/project-omega/forks","keys_url":"https://api.github.com/repos/koushikmln/project-omega/keys{/key_id}","collaborators_url":"https://api.github.com/repos/koushikmln/project-omega/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/koushikmln/project-omega/teams","hooks_url":"https://api.github.com/repos/koushikmln/project-omega/hooks","issue_events_url":"https://api.github.com/repos/koushikmln/project-omega/issues/events{/number}","events_url":"https://api.github.com/repos/koushikmln/project-omega/events","assignees_url":"https://api.github.com/repos/koushikmln/project-omega/assignees{/user}","branches_url":"https://api.github.com/repos/koushikmln/project-omega/branches{/branch}","tags_url":"https://api.github.com/repos/koushikmln/project-omega/tags","blobs_url":"https://api.github.com/repos/koushikmln/project-omega/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/koushikmln/project-omega/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/koushikmln/project-omega/git/refs{/sha}","trees_url":"https://api.github.com/repos/koushikmln/project-omega/git/trees{/sha}","statuses_url":"https://api.github.com/repos/koushikmln/project-omega/statuses/{sha}","languages_url":"https://api.github.com/repos/koushikmln/project-omega/languages","stargazers_url":"https://api.github.com/repos/koushikmln/project-omega/stargazers","contributors_url":"https://api.github.com/repos/koushikmln/project-omega/contributors","subscribers_url":"https://api.github.com/repos/koushikmln/project-omega/subscribers","subscription_url":"https://api.github.com/repos/koushikmln/project-omega/subscription","commits_url":"https://api.github.com/repos/koushikmln/project-omega/commits{/sha}","git_commits_url":"https://api.github.com/repos/koushikmln/project-omega/git/commits{/sha}","comments_url":"https://api.github.com/repos/koushikmln/project-omega/comments{/number}","issue_comment_url":"https://api.github.com/repos/koushikmln/project-omega/issues/comments{/number}","contents_url":"https://api.github.com/repos/koushikmln/project-omega/contents/{+path}","compare_url":"https://api.github.com/repos/koushikmln/project-omega/compare/{base}...{head}","merges_url":"https://api.github.com/repos/koushikmln/project-omega/merges","archive_url":"https://api.github.com/repos/koushikmln/project-omega/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/koushikmln/project-omega/downloads","issues_url":"https://api.github.com/repos/koushikmln/project-omega/issues{/number}","pulls_url":"https://api.github.com/repos/koushikmln/project-omega/pulls{/number}","milestones_url":"https://api.github.com/repos/koushikmln/project-omega/milestones{/number}","notifications_url":"https://api.github.com/repos/koushikmln/project-omega/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/koushikmln/project-omega/labels{/name}","releases_url":"https://api.github.com/repos/koushikmln/project-omega/releases{/id}","deployments_url":"https://api.github.com/repos/koushikmln/project-omega/deployments","created_at":"2017-03-12T12:45:53Z","updated_at":"2017-03-13T18:41:23Z","pushed_at":"2017-03-30T15:58:12Z","git_url":"git://github.com/koushikmln/project-omega.git","ssh_url":"git@github.com:koushikmln/project-omega.git","clone_url":"https://github.com/koushikmln/project-omega.git","svn_url":"https://github.com/koushikmln/project-omega","homepage":"","size":8,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"kaustubh-karkare:master","ref":"master","sha":"0db6beb9fe31f9252e0a42c128e483247155b92d","user":{"login":"kaustubh-karkare","id":1102450,"avatar_url":"https://avatars3.githubusercontent.com/u/1102450?v=3","gravatar_id":"","url":"https://api.github.com/users/kaustubh-karkare","html_url":"https://github.com/kaustubh-karkare","followers_url":"https://api.github.com/users/kaustubh-karkare/followers","following_url":"https://api.github.com/users/kaustubh-karkare/following{/other_user}","gists_url":"https://api.github.com/users/kaustubh-karkare/gists{/gist_id}","starred_url":"https://api.github.com/users/kaustubh-karkare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaustubh-karkare/subscriptions","organizations_url":"https://api.github.com/users/kaustubh-karkare/orgs","repos_url":"https://api.github.com/users/kaustubh-karkare/repos","events_url":"https://api.github.com/users/kaustubh-karkare/events{/privacy}","received_events_url":"https://api.github.com/users/kaustubh-karkare/received_events","type":"User","site_admin":false},"repo":{"id":82849815,"name":"project-omega","full_name":"kaustubh-karkare/project-omega","owner":{"login":"kaustubh-karkare","id":1102450,"avatar_url":"https://avatars3.githubusercontent.com/u/1102450?v=3","gravatar_id":"","url":"https://api.github.com/users/kaustubh-karkare","html_url":"https://github.com/kaustubh-karkare","followers_url":"https://api.github.com/users/kaustubh-karkare/followers","following_url":"https://api.github.com/users/kaustubh-karkare/following{/other_user}","gists_url":"https://api.github.com/users/kaustubh-karkare/gists{/gist_id}","starred_url":"https://api.github.com/users/kaustubh-karkare/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kaustubh-karkare/subscriptions","organizations_url":"https://api.github.com/users/kaustubh-karkare/orgs","repos_url":"https://api.github.com/users/kaustubh-karkare/repos","events_url":"https://api.github.com/users/kaustubh-karkare/events{/privacy}","received_events_url":"https://api.github.com/users/kaustubh-karkare/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kaustubh-karkare/project-omega","description":null,"fork":false,"url":"https://api.github.com/repos/kaustubh-karkare/project-omega","forks_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/forks","keys_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/teams","hooks_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/hooks","issue_events_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/issues/events{/number}","events_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/events","assignees_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/assignees{/user}","branches_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/branches{/branch}","tags_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/tags","blobs_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/git/refs{/sha}","trees_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/statuses/{sha}","languages_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/languages","stargazers_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/stargazers","contributors_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/contributors","subscribers_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/subscribers","subscription_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/subscription","commits_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/commits{/sha}","git_commits_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/git/commits{/sha}","comments_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/comments{/number}","issue_comment_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/issues/comments{/number}","contents_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/contents/{+path}","compare_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/merges","archive_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/downloads","issues_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/issues{/number}","pulls_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/pulls{/number}","milestones_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/milestones{/number}","notifications_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/labels{/name}","releases_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/releases{/id}","deployments_url":"https://api.github.com/repos/kaustubh-karkare/project-omega/deployments","created_at":"2017-02-22T20:34:46Z","updated_at":"2017-03-29T05:27:07Z","pushed_at":"2017-03-30T15:58:14Z","git_url":"git://github.com/kaustubh-karkare/project-omega.git","ssh_url":"git@github.com:kaustubh-karkare/project-omega.git","clone_url":"https://github.com/kaustubh-karkare/project-omega.git","svn_url":"https://github.com/kaustubh-karkare/project-omega","homepage":"","size":10,"stargazers_count":1,"watchers_count":1,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":12,"mirror_url":null,"open_issues_count":22,"forks":12,"open_issues":22,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kaustubh-karkare/project-omega/pulls/6"},"html":{"href":"https://github.com/kaustubh-karkare/project-omega/pull/6"},"issue":{"href":"https://api.github.com/repos/kaustubh-karkare/project-omega/issues/6"},"comments":{"href":"https://api.github.com/repos/kaustubh-karkare/project-omega/issues/6/comments"},"review_comments":{"href":"https://api.github.com/repos/kaustubh-karkare/project-omega/pulls/6/comments"},"review_comment":{"href":"https://api.github.com/repos/kaustubh-karkare/project-omega/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/kaustubh-karkare/project-omega/pulls/6/commits"},"statuses":{"href":"https://api.github.com/repos/kaustubh-karkare/project-omega/statuses/c739287e80637c3b0af5b4d8608ba4e550e5d92f"}}}}
{"actor":{"display_login":"kaustubh-karkare"}}