Skip to content

Commit

Permalink
Python 3: thread -> threading
Browse files Browse the repository at this point in the history
  • Loading branch information
mgedmin committed Oct 21, 2017
1 parent fd0030e commit 56c46d0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/zope/server/serverchannelbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
import time
import sys
import asyncore
from thread import allocate_lock
from threading import Lock
from zope.interface import implementer

from zope.server.dualmodechannel import DualModeChannel
from zope.server.interfaces import IServerChannel, ITask

# task_lock is useful for synchronizing access to task-related attributes.
task_lock = allocate_lock()
task_lock = Lock()


@implementer(IServerChannel, ITask)
Expand Down
12 changes: 8 additions & 4 deletions src/zope/server/taskthreads.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
##############################################################################
"""Threaded Task Dispatcher
"""
from Queue import Queue, Empty
from thread import allocate_lock, start_new_thread
import threading
try:
from Queue import Queue, Empty
except ImportError:
from queue import Queue, Empty
from time import time, sleep
import logging

Expand All @@ -34,7 +37,7 @@ class ThreadedTaskDispatcher(object):
def __init__(self):
self.threads = {} # { thread number -> 1 }
self.queue = Queue()
self.thread_mgmt_lock = allocate_lock()
self.thread_mgmt_lock = threading.Lock()

def handlerThread(self, thread_no):
threads = self.threads
Expand Down Expand Up @@ -74,7 +77,8 @@ def setThreadCount(self, count):
thread_no = thread_no + 1
threads[thread_no] = 1
running += 1
start_new_thread(self.handlerThread, (thread_no,))
threading.Thread(target=self.handlerThread,
args=(thread_no,)).start()
thread_no = thread_no + 1
if running > count:
# Stop threads.
Expand Down
4 changes: 2 additions & 2 deletions src/zope/server/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import os
import socket
import struct
import thread
from threading import Lock
import errno

_ADDRESS_MASK = 256 ** struct.calcsize('P')
Expand Down Expand Up @@ -72,7 +72,7 @@ def __init__(self):

# `lock` protects the `thunks` list from being traversed and
# appended to simultaneously.
self.lock = thread.allocate_lock()
self.lock = Lock()

# List of no-argument callbacks to invoke when the trigger is
# pulled. These run in the thread running the asyncore mainloop,
Expand Down

0 comments on commit 56c46d0

Please sign in to comment.