Skip to content

Commit

Permalink
Create tmporary directory for dumpCell request
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanMabille committed Feb 23, 2021
1 parent 0940d9f commit c95a7b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 6 additions & 2 deletions ipykernel/compiler.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from IPython.core.compilerop import CachingCompiler
import murmurhash.mrmr
import tempfile
import os

def get_tmp_directory():
return '/tmp/ipykernel_debugger/'
tmp_dir = tempfile.gettempdir()
pid = os.getpid()
return tmp_dir + '/ipykernel_' + str(pid)

def get_tmp_hash_seed():
hash_seed = 0xc70f6907
Expand All @@ -12,7 +16,7 @@ def get_file_name(code):
name = murmurhash.mrmr.hash(code, seed = get_tmp_hash_seed(), murmur_version=2)
if name < 0:
name += 2**32
return get_tmp_directory() + str(name) + '.py'
return get_tmp_directory() + '/' + str(name) + '.py'

class XCachingCompiler(CachingCompiler):

Expand Down
7 changes: 4 additions & 3 deletions ipykernel/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from .compiler import (get_file_name, get_tmp_directory, get_tmp_hash_seed)

import debugpy
import time

class DebugpyMessageQueue:

Expand Down Expand Up @@ -163,7 +162,6 @@ def get_host_port(self):
self.debugpy_port = self.endpoint[index+1:]
return self.debugpy_host, self.debugpy_port


def connect_tcp_socket(self):
self.debugpy_stream.socket.connect(self._get_endpoint())
self.routing_id = self.debugpy_stream.socket.getsockopt(zmq.ROUTING_ID)
Expand Down Expand Up @@ -238,6 +236,9 @@ def tcp_client(self):

def start(self):
if not self.debugpy_initialized:
tmp_dir = get_tmp_directory()
if not os.path.exists(tmp_dir):
os.makedirs(tmp_dir)
host, port = self.debugpy_client.get_host_port()
code = 'import debugpy;'
code += 'debugpy.listen(("' + host + '",' + port + '))'
Expand Down Expand Up @@ -350,7 +351,7 @@ async def debugInfo(self, message):
'isStarted': self.is_started,
'hashMethod': 'Murmur2',
'hashSeed': get_tmp_hash_seed(),
'tmpFilePrefix': get_tmp_directory(),
'tmpFilePrefix': get_tmp_directory() + '/',
'tmpFileSuffix': '.py',
'breakpoints': breakpoint_list,
'stoppedThreads': self.stopped_threads
Expand Down

0 comments on commit c95a7b1

Please sign in to comment.